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 7. Eduardo Díaz Estrada #39

Open
wants to merge 8 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
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.18)
multi_json (1.3.1)
multi_json (1.3.2)
orm_adapter (0.0.7)
paperclip (3.0.2)
activemodel (>= 3.0.0)
Expand Down Expand Up @@ -95,7 +95,7 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
sass (3.1.15)
sass (3.1.16)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
Expand All @@ -104,7 +104,7 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
sqlite3 (1.3.6)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
Expand Down
51 changes: 51 additions & 0 deletions Gemfile~
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
source 'https://rubygems.org'

gem 'rails', '3.2.2'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

group :development, :test do
gem 'sqlite3'
end

group :production do
gem 'pg'
end


gem 'devise'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer'

gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'
gem 'cleditor_rails'
gem 'paperclip'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

#gem 'json', '1.6.5'

Binary file added app/assets/images/foto.jpg
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/
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/
16 changes: 16 additions & 0 deletions app/assets/stylesheets/planet.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@
font-size: small;
}

#search {
float: right;
position: relative;

margin-right: 1em;
margin-top: 14px;


}

#map_canvas {
margin-left: 9em; /* Ajuste de borde izquierdo */
padding-top: 4ex;
padding-left: 2em;
}

#columns {
background: #446;
}
Expand Down
90 changes: 90 additions & 0 deletions app/controllers/comentarios_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#ComentariosController es la clase que aglutina los métodos
#necesarios para tratar con los comentarios creados en un determinado sitio
#
class ComentariosController < ApplicationController



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

# Método que devuelve todos los comentarios existentes
def index

@comentarios=Comentario.all

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

#método que muestra los comentarios correspondientes a un determinado sitio
def show
@comentario = Comentario.find(params[:id])

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

# método que crea un nuevo comentario "vacío"
def new
@comentario = Comentario.new

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

#método que se emplea para editar un nuevo comentario
def edit
@comentario = Comentario.find(params[:id])
end

#método que crea un nuevo comentario asociado a un determinado sitio
def create
@site=Site.find(params[:site_id])
@[email protected](params[:comentario])
@comentario.user_id=current_user.id


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

#método empleado para actualizar un comentario
def update
@comentario = current_user.comentarios.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

#método para eliminar un comentario determinado
def destroy
@comentario = current_user.comentarios.find(params[:id])
@comentario.destroy

respond_to do |format|
format.html { redirect_to @comentario, notice: 'Comentario was successfully destroyed.' }
format.json { render json: @comentario, status: :created, location: @comentario }
end
end
end
10 changes: 10 additions & 0 deletions app/controllers/planet_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,15 @@ 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 define la acción de buscar en el controlador
def search

@sites = Site.where("name like ? OR description like ?", "%#{params[:search]}%", "%#{params[:search]}%")
@trips = Trip.where("name like ? OR description like ?", "%#{params[:search]}%", "%#{params[:search]}%")

end

end
32 changes: 17 additions & 15 deletions app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#SitesController es la clase que aglutina los métodos
#necesarios para tratar con los sitios registrados en el sistema
#
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

# GET /sites
# GET /sites.json
#método que muestra todos los sitios creados
def index
if params[:type_id].nil? or params[:type_id].empty?
@sites = Site.all # path: /types
Expand All @@ -18,19 +22,19 @@ def index
end
end

# GET /sites/1
# GET /sites/1.json
# método que muestra el sitio con un determinado id
def show
@site = Site.find(params[:id])

@comentario=Comentario.new(:site=>@site)

respond_to do |format|
format.html # show.html.erb
format.json { render json: @site }
end
end

# GET /sites/new
# GET /sites/new.json
#método que crea un nuevo sitio vacío
def new
@site = current_user.sites.build # crea sitio vacio asociado a current_user

Expand All @@ -40,13 +44,12 @@ def new
end
end

# GET /sites/1/edit
# método para editar un sitio creado con anterioridad
def edit
@site = current_user.sites.find(params[:id]) # busca solo en sitios asociados a current_user
end

# POST /sites
# POST /sites.json
# método necesario para crear un nuevo sitio asignado a un usuario
def create
@site = current_user.sites.build(params[:site]) # Asigna solo si sitio asociado a current_user

Expand All @@ -61,8 +64,7 @@ def create
end
end

# PUT /sites/1
# PUT /sites/1.json
# método para actualizar sitios creados por un usuario
def update
@site = current_user.sites.find(params[:id]) # busca solo en sitios asociados a current_user

Expand All @@ -77,8 +79,7 @@ def update
end
end

# DELETE /sites/1
# DELETE /sites/1.json
#método para eleminar los sitios creados por el usuario
def destroy
@site = current_user.sites.find(params[:id]) # busca solo en sitios asociados a current_user
@site.destroy
Expand All @@ -88,9 +89,10 @@ def destroy
format.json { head :no_content }
end
end

private
def count_visita
@site.increment!(:visitas)
end
end

end
24 changes: 11 additions & 13 deletions app/controllers/trips_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#TripsController es la clase que aglutina los métodos
#necesarios para tratar con los viajes creados
#
class TripsController < ApplicationController


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

# GET /trips
# GET /trips.json
# método que muestra todos los viajes disponibles
def index
@trips = Trip.all

Expand All @@ -14,8 +17,7 @@ def index
end
end

# GET /trips/1
# GET /trips/1.json
# método que muestra un determinado viaje
def show
@trip = Trip.find(params[:id])
@visit = @trip.visits.build
Expand All @@ -26,8 +28,7 @@ def show
end
end

# GET /trips/new
# GET /trips/new.json
# método que crea un nuevo viaje vacío
def new
@trip = current_user.trips.build

Expand All @@ -37,13 +38,12 @@ def new
end
end

# GET /trips/1/edit
# método para editar un viaje
def edit
@trip = current_user.trips.find(params[:id])
end

# POST /trips
# POST /trips.json
# método para crear un nuevo viaje asociado al usuario actual
def create
@trip = current_user.trips.build(params[:trip])

Expand All @@ -58,8 +58,7 @@ def create
end
end

# PUT /trips/1
# PUT /trips/1.json
# método para actualizar un viaje determinado
def update
@trip = current_user.trips.find(params[:id])

Expand All @@ -74,8 +73,7 @@ def update
end
end

# DELETE /trips/1
# DELETE /trips/1.json
# método para eliminar un viaje determinado
def destroy
@trip = current_user.trips.find(params[:id])
@trip.destroy
Expand Down
Loading