Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entrega 6 #40

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ gem 'rails', '3.2.2'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

group :development do
gem 'sqlite3'
end

group :production do
gem 'pg'
end

gem 'sqlite3'

gem 'devise'

Expand Down
9 changes: 4 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ GEM
mime-types (1.17.2)
multi_json (1.1.0)
orm_adapter (0.0.7)
paperclip (2.4.5)
activerecord (>= 2.3.0)
activesupport (>= 2.3.2)
paperclip (3.0.2)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (>= 0.0.2)
mime-types
pg (0.13.2)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
Expand Down Expand Up @@ -125,7 +125,6 @@ DEPENDENCIES
devise
jquery-rails
paperclip
pg
rails (= 3.2.2)
sass-rails (~> 3.2.3)
sqlite3
Expand Down
Binary file added app/assets/images/auto1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/auto2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/beachflag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/coliseo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/javascripts/comentarios.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
9 changes: 9 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@
*= require cleditor
*= require_tree .
*/


#container{}
#enla1{}
#enla1 a{color:blue;}
#cuerpo{}



4 changes: 4 additions & 0 deletions app/assets/stylesheets/author.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#espa{background-color:green;color:green;}
.autor1{}
#espacio{background-color:blue;color:blue;}
.autor2{}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/comentarios.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the comentarios controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
6 changes: 0 additions & 6 deletions app/assets/stylesheets/planet.css
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,3 @@
font-weight: bold;
margin-right: 2em;
}


#main .visitas {
text-indent: 70%;
}

3 changes: 3 additions & 0 deletions app/assets/stylesheets/sites.css.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Place all the styles related to the sites controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

#comentarios a{font-weight:bold;color:red;}

2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Controlador de la aplicacion.
#
class ApplicationController < ActionController::Base
protect_from_forgery
end
87 changes: 87 additions & 0 deletions app/controllers/comentarios_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Controlador de los comentarios donde se definen sus metodos
#
class ComentariosController < ApplicationController

before_filter :authenticate_user!

# GET /comentarios
# GET /comentarios.json
def index
@comentarios = Comentario.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @comentarios }
end
end

# GET /comentarios/1
# GET /comentarios/1.json
def show
@comentario = Comentario.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @comentario }
end
end

# GET /comentarios/new
# GET /comentarios/new.json
def new
@comentario = Comentario.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @comentario }
end
end

# GET /comentarios/1/edit
def edit
@comentario = Comentario.find(params[:id])
end

# POST /comentarios
# POST /comentarios.json
def create
@comentario = Comentario.new(params[:comentario])

respond_to do |format|
if @comentario.save
format.html { redirect_to @comentario, notice: 'Comentario was successfully created.' }
format.json { render json: @comentario, status: :created, location: @comentario }
else
format.html { render action: "new" }
format.json { render json: @comentario.errors, status: :unprocessable_entity }
end
end
end

# PUT /comentarios/1
# PUT /comentarios/1.json
def update
@comentario = Comentario.find(params[:id])

respond_to do |format|
if @comentario.update_attributes(params[:comentario])
format.html { redirect_to @comentario, notice: 'Comentario was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @comentario.errors, status: :unprocessable_entity }
end
end
end

# DELETE /comentarios/1
# DELETE /comentarios/1.json
def destroy
@comentario = Comentario.find(params[:id])
@comentario.destroy

respond_to do |format|
format.html { redirect_to comentarios_url }
format.json { head :no_content }
end
end
end
14 changes: 13 additions & 1 deletion app/controllers/planet_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,17 @@ def contact
# Método que define una acción vacía del controlador
def ejemplo
end

# Método que define una acción vacía del controlador
def author
end
# Método que realiza la busqueda de sitios y viajes
def search
if params[:q].length >= 3
@sites = Site.where("name like ? OR description like ?", "%#{params[:q]}%", "%#{params[:q]}%")
@trips = Trip.where("name like ? OR description like ?", "%#{params[:q]}%", "%#{params[:q]}%")
else
render action: "busquedaincorrecta"
end
end

end
22 changes: 17 additions & 5 deletions app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Controlador de los sitios donde se definen sus metodos
#
class SitesController < ApplicationController

# authenticate_user! ejecuta acción solo si sesión existe
before_filter :authenticate_user!, :except => [ :index, :show ]
after_filter :count_visita, :only => :show

after_filter :count_visita, :only => :show


# GET /sites
# GET /sites.json
def index
Expand All @@ -17,12 +20,21 @@ def index
format.json { render json: @sites }
end
end
# GET
# GET /sites.json
def id
@sites = Visit.find(params[:user_id]).sites # path: /types/id/sites
respond_to do |format|
format.html # index.html.erb
format.json { render json: @sites }
end
end

# GET /sites/1
# GET /sites/1.json
def show
@site = Site.find(params[:id])

@comentarios = @site.comentarios
respond_to do |format|
format.html # show.html.erb
format.json { render json: @site }
Expand Down Expand Up @@ -88,8 +100,8 @@ def destroy
format.json { head :no_content }
end
end
private
private
#Incrementa visita cuando se accede al sitio
def count_visita
@site.increment!(:visitas)
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/trips_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Controlador de los viajes donde se definen sus metodos
#
class TripsController < ApplicationController

# authenticate_user! ejecuta acción solo si sesión existe
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/types_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
# Controlador de los tipos donde se definen sus metodos
#
class TypesController < ApplicationController

# GET /types/ordered_index
# GET /types.json
def ordered_index
@types = Type.find(:all, :order => :name)
respond_to do |format|
format.html # ordered_index.html.erb
format.json { render json: @types }
end
end

# GET /types
# GET /types.json
def index
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/visits_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Controlador de las visitas donde se definen sus metodos
#
class VisitsController < ApplicationController
# GET /visits
# GET /visits.json
Expand Down Expand Up @@ -45,7 +47,6 @@ def create
respond_to do |format|
if @visit.save
format.html { redirect_to @visit.trip, notice: 'Visit was successfully created.' }
format.js
format.json { render json: @visit, status: :created, location: @visit }
else
format.html { render action: "new" }
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Helper de la clase Application
#
module ApplicationHelper
end
4 changes: 4 additions & 0 deletions app/helpers/comentarios_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Helper de la clase Comentarios
#
module ComentariosHelper
end
2 changes: 2 additions & 0 deletions app/helpers/planet_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Helper de la clase Planet
#
module PlanetHelper
end
1 change: 1 addition & 0 deletions app/helpers/sites_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Helper de la clase Sites
module SitesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/trips_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Helper de la clase Trips
#
module TripsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/types_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Helper de la clase Types
#
module TypesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/visits_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Helper de la clase Visit
#
module VisitsHelper
end
11 changes: 11 additions & 0 deletions app/models/comentario.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Se definen las relaciones de la clase Comentario
#
class Comentario < ActiveRecord::Base
belongs_to :user
belongs_to :site

validates :coment, :site_id, :user_id, :length => {:maximum => 240}, :presence => true
# Debe estar protegido para evitar accesos indeseados
#attr_protected :user_id

end
7 changes: 5 additions & 2 deletions app/models/site.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Se definen las relaciones de la clase Site
#
class Site < ActiveRecord::Base
belongs_to :type
belongs_to :user
has_many :visits
has_many :trips, :through => :visits
has_many :trips, :through => :visits
has_many :comentarios
has_attached_file :image


# Debe estar protegido para evitar accesos indeseados
attr_protected :user_id

# Se añaden estas definiciones
validates :name, :type_id, :presence => true # campo obligatorio
validates :name, :type_id, :presence => true # campo obligatorio
end
2 changes: 2 additions & 0 deletions app/models/trip.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Se definen las relaciones de la clase Trip
#
class Trip < ActiveRecord::Base
belongs_to :user
has_many :visits
Expand Down
2 changes: 2 additions & 0 deletions app/models/type.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Se definen las relaciones de la clase Type
#
class Type < ActiveRecord::Base
has_many :sites

Expand Down
10 changes: 10 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# Se definen las relaciones de la clase User
#
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me

has_many :sites
has_many :trips
has_many :comentarios

# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
Expand Down
2 changes: 2 additions & 0 deletions app/models/visit.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Se definen las relaciones de la clase Visit
#
class Visit < ActiveRecord::Base
belongs_to :trip
belongs_to :site
Expand Down
Loading