<%= notice %>
<%= alert %>
+ +<%= notice %>
<%= alert %>
<%= yield %> ++
+
+ <%= link_to "Home", planet_index_path %>| <%= link_to "Sitios", sites_path %>| <%= link_to "Tipos", types_path %>|<%= link_to "Contact", planet_contact_path %>
diff --git a/Gemfile.lock b/Gemfile.lock index fd905dc..53fc807 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) diff --git a/Gemfile~ b/Gemfile~ new file mode 100644 index 0000000..f3540ce --- /dev/null +++ b/Gemfile~ @@ -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' + diff --git a/app/assets/images/foto.jpg b/app/assets/images/foto.jpg new file mode 100644 index 0000000..79bc033 Binary files /dev/null and b/app/assets/images/foto.jpg differ diff --git a/app/assets/javascripts/comentarios.js.coffee b/app/assets/javascripts/comentarios.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/comentarios.js.coffee @@ -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/ diff --git a/app/assets/stylesheets/comentarios.css.scss b/app/assets/stylesheets/comentarios.css.scss new file mode 100644 index 0000000..494c101 --- /dev/null +++ b/app/assets/stylesheets/comentarios.css.scss @@ -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/ diff --git a/app/assets/stylesheets/planet.css b/app/assets/stylesheets/planet.css index ead053a..9a73c71 100644 --- a/app/assets/stylesheets/planet.css +++ b/app/assets/stylesheets/planet.css @@ -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; } diff --git a/app/controllers/comentarios_controller.rb b/app/controllers/comentarios_controller.rb new file mode 100644 index 0000000..becec6a --- /dev/null +++ b/app/controllers/comentarios_controller.rb @@ -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]) + @comentario=@site.comentarios.create(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 \ No newline at end of file diff --git a/app/controllers/planet_controller.rb b/app/controllers/planet_controller.rb index a8636bd..3fa4183 100644 --- a/app/controllers/planet_controller.rb +++ b/app/controllers/planet_controller.rb @@ -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 diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index 57e0611..833a5c8 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -88,9 +89,10 @@ def destroy format.json { head :no_content } end end - + private def count_visita @site.increment!(:visitas) end -end + +end \ No newline at end of file diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 321f6e3..cdd49e2 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -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 @@ -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 @@ -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 @@ -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]) @@ -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]) @@ -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 diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rb index da826f4..de56559 100644 --- a/app/controllers/types_controller.rb +++ b/app/controllers/types_controller.rb @@ -1,6 +1,10 @@ +#TypesController es la clase que aglutina los métodos +#necesarios para tratar con las tipos de lugares del sistema +# class TypesController < ApplicationController - # GET /types - # GET /types.json + + +#método que muestra todos los tipos disponibles def index @types = Type.all @@ -10,8 +14,7 @@ def index end end - # GET /types/1 - # GET /types/1.json + #método qeu muestra un determinado tipo creado def show @type = Type.find(params[:id]) @@ -21,8 +24,7 @@ def show end end - # GET /types/new - # GET /types/new.json + #método que crea un nuevo tipo vacío def new @type = Type.new @@ -32,13 +34,12 @@ def new end end - # GET /types/1/edit + #método que edita un tipo creado anteriormente def edit @type = Type.find(params[:id]) end - # POST /types - # POST /types.json + #método que crea nuevo un tipo determinado def create @type = Type.new(params[:type]) @@ -53,8 +54,7 @@ def create end end - # PUT /types/1 - # PUT /types/1.json + # método que actualiza un tipo creado previamente def update @type = Type.find(params[:id]) @@ -69,8 +69,7 @@ def update end end - # DELETE /types/1 - # DELETE /types/1.json + # método para eliminar un tipo existente def destroy @type = Type.find(params[:id]) @type.destroy @@ -80,4 +79,19 @@ def destroy format.json { head :no_content } end end + + +#método que devuelve los tipos ordenados alfabéticamente + +def ordered_index + + @types=Type.find(:all, :order => :name) + + respond_to do |format| + format.html #index.html.erb + format.json { render json: @types} +end + +end + end diff --git a/app/controllers/visits_controller.rb b/app/controllers/visits_controller.rb index 5bd5366..641a0ae 100644 --- a/app/controllers/visits_controller.rb +++ b/app/controllers/visits_controller.rb @@ -1,6 +1,9 @@ +#VisitsController es la clase que aglutina los métodos +#necesarios para tratar con las visitas a un determinado lugar class VisitsController < ApplicationController - # GET /visits - # GET /visits.json + + + #método que muestra todas las visitas def index @visits = Visit.all @@ -10,8 +13,7 @@ def index end end - # GET /visits/1 - # GET /visits/1.json + #método que muestra las visitas de un determinado lugar def show @visit = Visit.find(params[:id]) @@ -21,8 +23,7 @@ def show end end - # GET /visits/new - # GET /visits/new.json + #método que crea una nueva visita vacía def new @visit = Visit.new @@ -32,13 +33,12 @@ def new end end - # GET /visits/1/edit + # método para editar visitas def edit @visit = Visit.find(params[:id]) end - # POST /visits - # POST /visits.json + # método que crea una visita y la asocia a un lugar determinado def create @visit = Visit.new(params[:visit]) @@ -54,8 +54,7 @@ def create end end - # PUT /visits/1 - # PUT /visits/1.json + # método para actualizar las visitas de un lugar def update @visit = Visit.find(params[:id]) @@ -70,8 +69,7 @@ def update end end - # DELETE /visits/1 - # DELETE /visits/1.json + # método que elimina las visitas de un lugar def destroy @visit = Visit.find(params[:id]) @visit.destroy diff --git a/app/helpers/comentarios_helper.rb b/app/helpers/comentarios_helper.rb new file mode 100644 index 0000000..a8f928b --- /dev/null +++ b/app/helpers/comentarios_helper.rb @@ -0,0 +1,2 @@ +module ComentariosHelper +end diff --git a/app/models/comentario.rb b/app/models/comentario.rb new file mode 100644 index 0000000..bff3005 --- /dev/null +++ b/app/models/comentario.rb @@ -0,0 +1,12 @@ +#Comentario muestra las relaciones de la tabla comentarios en el modelo de datos. +# +# == Relaciones +# +# * Un comentario pertenece a un trip. +# * Un comentario pertenece a un site. +# +class Comentario < ActiveRecord::Base + + belongs_to :site + belongs_to :user +end diff --git a/app/models/site.rb b/app/models/site.rb index 2b2f99a..58a191d 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -1,9 +1,21 @@ +#Site muestra las relaciones de la tabla site en el modelo de datos. +# +# == Relaciones +# +# * Un sitio pertenece a un tipo. +# * Un sitio pertenece a un usuario. +# * Un sitio puede tener muchas visitas. +# * Un sitio puede tener muchos viajes. +# * Un sitio puede tener muchos comentarios. +# * Un sitio tiene una imagen asociada. +# class Site < ActiveRecord::Base belongs_to :type belongs_to :user has_many :visits has_many :trips, :through => :visits has_attached_file :image + has_many :comentarios # Debe estar protegido para evitar accesos indeseados diff --git a/app/models/trip.rb b/app/models/trip.rb index 4ff6d83..7942d82 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -1,3 +1,11 @@ +# Trip muestra las relaciones de la tabla trip en el modelo de datos. +# +# == Relaciones +# +# * Un viaje puede tener muchas visitas. +# * Un viaje puede tener muchos sitios. +# * Un viaje pertenece a un usuario. +# class Trip < ActiveRecord::Base belongs_to :user has_many :visits diff --git a/app/models/type.rb b/app/models/type.rb index 2284d1f..5ce49d2 100644 --- a/app/models/type.rb +++ b/app/models/type.rb @@ -1,3 +1,12 @@ +#Type muestra las relaciones de la tabla type en el modelo de datos. +# +# == Relaciones +# +# Tal y como muestra el subitulo anterior, este se define empezando la +# línea con ==. En los títulos debe empezar por =. +# +# * Un type puede tener muchos sitios. +# class Type < ActiveRecord::Base has_many :sites diff --git a/app/models/user.rb b/app/models/user.rb index 35b8159..1cc1ea7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,16 @@ +#User muestra las relaciones de la tabla user en el modelo de datos. +# +# == Relaciones +# +# * Un usuario puede tener muchos sitios. +# * Un usuario puede tener muchos viajes. +# * Un usuario puede tener muchos comentarios. +# class User < ActiveRecord::Base has_many :sites has_many :trips + has_many :comentarios # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable diff --git a/app/models/visit.rb b/app/models/visit.rb index 57546da..c49ad3c 100644 --- a/app/models/visit.rb +++ b/app/models/visit.rb @@ -1,3 +1,10 @@ +#Visit muestra las relaciones de la tabla visit en el modelo de datos. +# +# == Relaciones +# +# * Una visita pertenece a un viaje. +# * Una visita pertenece a un sitio. +# class Visit < ActiveRecord::Base belongs_to :trip belongs_to :site diff --git a/app/views/comentarios/_form.html.erb b/app/views/comentarios/_form.html.erb new file mode 100644 index 0000000..85a0741 --- /dev/null +++ b/app/views/comentarios/_form.html.erb @@ -0,0 +1,30 @@ +<%= form_for(@comentario) do |f| %> + <% if @comentario.errors.any? %> +
<%= comentario.user.name if comentario.user %> | + +
+
|
+
+
+ <% if comentario.user == current_user %>
+ <%= link_to 'Edit', edit_comentario_path(comentario) %> + <%= link_to 'Destroy', comentario, confirm: 'Are you sure?', method: :delete %> + <% end %> + |
+
<%= notice %>
+ ++ Comentario: + <%= @comentario.coment %> +
+ ++ Autor: + <%= @comentario.user.name if @comentario.user %> +
+ ++ Site: + <%= @comentario.site.name if @comentario.site %> +
+ +<% if @comentario.user == current_user %> + <%= link_to 'Edit', edit_comentario_path(@comentario) %> + <%= link_to 'Destroy', @comentario, confirm: 'Are you sure?', method: :delete %> + <% end %> +<%= link_to 'Back', site_path(@comentario.site_id) %> \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e4c9e36..af4c813 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -6,7 +6,11 @@ <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> - + @@ -14,22 +18,56 @@