diff --git a/Gemfile b/Gemfile
index ec2ba7b..6c09448 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,16 +2,19 @@ source 'https://rubygems.org'
gem 'rails', '3.2.2'
+ gem 'execjs'
+ gem 'therubyracer'
+
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
+gem 'sqlite3'
+#group :development, :test do
+# gem 'sqlite3'
+#end
-group :development, :test do
- gem 'sqlite3'
-end
-
-group :production do
- gem 'pg'
-end
+#group :production do
+# gem 'pg'
+#end
gem 'devise'
@@ -47,5 +50,5 @@ gem 'paperclip'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
-gem 'json', '1.6.5'
+# gem 'json', '1.6.5'
diff --git a/Gemfile.lock b/Gemfile.lock
index fd905dc..f11e3d2 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -54,13 +54,14 @@ GEM
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
- json (1.6.5)
+ json (1.6.6)
+ libv8 (3.3.10.4)
mail (2.4.4)
i18n (>= 0.4.0)
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)
@@ -68,7 +69,6 @@ GEM
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)
@@ -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,9 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- sqlite3 (1.3.5)
+ sqlite3 (1.3.6)
+ therubyracer (0.10.1)
+ libv8 (~> 3.3.10)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
@@ -124,11 +126,11 @@ DEPENDENCIES
cleditor_rails
coffee-rails (~> 3.2.1)
devise
+ execjs
jquery-rails
- json (= 1.6.5)
paperclip
- pg
rails (= 3.2.2)
sass-rails (~> 3.2.3)
sqlite3
+ therubyracer
uglifier (>= 1.0.3)
diff --git a/app/assets/images/antonio.jpg b/app/assets/images/antonio.jpg
new file mode 100644
index 0000000..ee737ce
Binary files /dev/null and b/app/assets/images/antonio.jpg differ
diff --git a/app/assets/images/favicon.ico b/app/assets/images/favicon.ico
new file mode 100644
index 0000000..2536afa
Binary files /dev/null and b/app/assets/images/favicon.ico differ
diff --git a/app/assets/images/fer.jpg b/app/assets/images/fer.jpg
new file mode 100644
index 0000000..137c3fb
Binary files /dev/null and b/app/assets/images/fer.jpg differ
diff --git a/app/assets/javascripts/comments.js.coffee b/app/assets/javascripts/comments.js.coffee
new file mode 100644
index 0000000..7615679
--- /dev/null
+++ b/app/assets/javascripts/comments.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/comments.css.scss b/app/assets/stylesheets/comments.css.scss
new file mode 100644
index 0000000..3722c12
--- /dev/null
+++ b/app/assets/stylesheets/comments.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the comments 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..5eec4d0 100644
--- a/app/assets/stylesheets/planet.css
+++ b/app/assets/stylesheets/planet.css
@@ -93,6 +93,15 @@
background: #446;
}
+#subirArriba {
+ float: right;
+}
+
+#bs{
+margin-top: 2em;
+width: 86px;
+}
+
#main {
margin-left: 9em; /* Ajuste de borde izquierdo */
padding-top: 4ex;
diff --git a/app/assets/stylesheets/planet.css~ b/app/assets/stylesheets/planet.css~
new file mode 100644
index 0000000..ead053a
--- /dev/null
+++ b/app/assets/stylesheets/planet.css~
@@ -0,0 +1,169 @@
+/* Global styles (no utilizados de momento) */
+
+#planet #notice {
+ color: #000;
+ border: 2px solid red;
+ padding: 1em;
+ margin-bottom: 2em;
+ background-color: #f0f0f0;
+ font: bold smaller sans-serif;
+}
+
+
+#planet h1 {
+ font: 150% sans-serif;
+ color: #226;
+ border-bottom: 3px dotted #77d;
+}
+
+/* Styles for products/index */
+
+#site_list table {
+ border-collapse: collapse;
+}
+
+#site_list table tr td {
+ padding: 5px;
+ vertical-align: top;
+}
+
+#site_list .list_image {
+ width: 60px;
+ height: 70px;
+}
+
+#site_list .list_description {
+ width: 60%;
+}
+
+#site_list .list_description dl {
+ margin: 0;
+}
+
+#site_list .list_description dt {
+ color: #244;
+ font-weight: bold;
+ font-size: larger;
+}
+
+#site_list .list_description dd {
+ margin: 0;
+}
+
+#site_list .list_actions {
+ font-size: x-small;
+ text-align: right;
+ padding-left: 1em;
+}
+
+#site_list .list_line_even {
+ background: #a8b8f8;
+}
+
+#site_list .list_line_odd {
+ background: #88b0f8;
+}
+
+
+/* START:mainlayout */
+/* Styles for main page */
+
+#banner {
+ background: #668;
+ padding-top: 10px;
+ padding-bottom: 10px;
+ border-bottom: 2px solid;
+ font: small-caps 40px/40px "Times New Roman", serif;
+ color: #bfb;
+ text-align: center;
+}
+
+#banner img {
+ float: left;
+ padding-left: 10px;
+}
+
+#banner .user {
+ float: right;
+ color: #bfb;
+ font-size: small;
+}
+
+#columns {
+ background: #446;
+}
+
+#main {
+ margin-left: 9em; /* Ajuste de borde izquierdo */
+ padding-top: 4ex;
+ padding-left: 2em;
+ background: white;
+}
+
+#side {
+ float: left;
+ padding-top: 1em;
+ padding-left: 1em;
+ padding-bottom: 1em;
+ width: 8em; /* Ajuste de borde izquierdo */
+ background: #446;
+}
+
+#side a {
+ color: #bfb;
+ font-size: small;
+}
+/* END:mainlayout */
+
+/* An entry in the store catalog (no utilizados de momento) */
+
+#planet .entry {
+ overflow: auto;
+ margin-top: 1em;
+ border-bottom: 1px dotted #77d;
+}
+
+#planet .name {
+ font-size: 120%;
+ font-family: sans-serif;
+}
+
+#store .entry img {
+ width: 80px;
+ margin-right: 5px;
+ margin-bottom: 5px;
+ float: left;
+}
+
+
+#store .entry h3 {
+ margin-top: 0;
+ margin-bottom: 2px;
+ color: #227;
+}
+
+#store .entry p {
+ margin-top: 0.5em;
+ margin-bottom: 0.8em;
+}
+
+#store .entry .price_line {
+ clear: both;
+ margin-bottom: 0.5em;
+}
+
+#store .entry .add_to_cart {
+ position: relative;
+}
+
+#store .entry .price {
+ color: #44a;
+ font-weight: bold;
+ margin-right: 2em;
+}
+
+
+#main .visitas {
+ text-indent: 70%;
+}
+
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index e8065d9..ac9622a 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,3 +1,6 @@
+# == En esta clase
+# [clase ApplicationController] Definimos instrucción para posibles ataques al servidor.
class ApplicationController < ActionController::Base
+
protect_from_forgery
end
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb
new file mode 100644
index 0000000..6cde408
--- /dev/null
+++ b/app/controllers/comments_controller.rb
@@ -0,0 +1,97 @@
+# Clase Ruby que hereda de +ApplicationController+.
+# Cuando la aplicación reciba una petición referente a comentarios, la ruta determina qué controlador y acción realizar.
+# == Métodos para controlador comentarios
+# * index
+# * show
+# * new
+# * edit
+# * create
+# * update
+# * destroy
+class CommentsController < ApplicationController
+ # GET /comments
+ # GET /comments.json
+ def index #gestiona las rutas anidadas
+ if params[:site_id].nil? or params[:site_id].empty?
+ @comments = Comment.all # path: /comment
+ else
+ @comments = Site.find(params[:site_id]).comments # path: /sites/id/comments
+ end
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @comments }
+ end
+ end
+
+ # GET /comments/1
+ # GET /comments/1.json
+ def show
+ @comment = Comment.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @comment }
+ end
+ end
+
+ # GET /comments/new
+ # GET /comments/new.json
+ def new
+ @comment = current_user.comments.build # crea comentario vacío asociado a current_user
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @comment }
+ end
+ end
+
+ # GET /comments/1/edit
+ def edit
+ @comment = current_user.comments.find(params[:id])
+ @site = @comment.site
+ end
+
+ # POST /comments
+ # POST /comments.json
+ def create
+ @comment = current_user.comments.build(params[:comment])
+
+ respond_to do |format|
+ if @comment.save
+ format.html { redirect_to @comment, notice: 'Comment was successfully created.' }
+ format.json { render json: @comment, status: :created, location: @comment }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @comment.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /comments/1
+ # PUT /comments/1.json
+ def update
+ @comment = current_user.comments.find(params[:id])
+
+ respond_to do |format|
+ if @comment.update_attributes(params[:comment])
+ format.html { redirect_to @comment, notice: 'Comment was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @comment.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /comments/1
+ # DELETE /comments/1.json
+ def destroy
+ @comment = Comment.find(params[:id])
+ @comment.destroy
+
+ respond_to do |format|
+ format.html { redirect_to comments_url }
+ format.json { head :no_content }
+ end
+ end
+end
diff --git a/app/controllers/comments_controller.rb~ b/app/controllers/comments_controller.rb~
new file mode 100644
index 0000000..2d0f2f0
--- /dev/null
+++ b/app/controllers/comments_controller.rb~
@@ -0,0 +1,97 @@
+# Clase Ruby que hereda de +ApplicationController+.
+# Cuando la aplicación reciba una petición referente a comentarios, la ruta determina qué controlador y acción realizar.
+# == Métodos para controlador comentarios
+# * index
+# * show
+# * new
+# * edit
+# * create
+# * update
+# * destroy
+class CommentsController < ApplicationController
+ # GET /comments
+ # GET /comments.json
+ def index #gestiona las rutas anidadas
+ if params[:site_id].nil? or params[:site_id].empty?
+ @comments = Comment.all # path: /comment
+ else
+ @comments = Site.find(params[:site_id]).comments # path: /sites/id/comments
+ end
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @comments }
+ end
+ end
+
+ # GET /comments/1
+ # GET /comments/1.json
+ def show
+ @comment = Comment.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @comment }
+ end
+ end
+
+ # GET /comments/new
+ # GET /comments/new.json
+ def new
+ @comment = current_user.comments.build # crea comentario vacío asociado a current_user
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @comment }
+ end
+ end
+
+ # GET /comments/1/edit
+ def edit
+ @comment = current_user.comments.find(params[:id])
+ @site = @comment.site
+ end
+
+ # POST /comments
+ # POST /comments.json
+ def create
+ @comment = current_user.comments.build(params[:comment])
+
+ respond_to do |format|
+ if @comment.save
+ format.html { redirect_to @comment, notice: 'Comment was successfully created.' }
+ format.json { render json: @comment, status: :created, location: @comment }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @comment.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /comments/1
+ # PUT /comments/1.json
+ def update
+ @comment = current_user.comments.find(params[:id])
+
+ respond_to do |format|
+ if @comment.update_attributes(params[:comment])
+ format.html { redirect_to @comment, notice: 'Comment was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @comment.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /comments/1
+ # DELETE /comments/1.json
+ def destroy
+ @comment = Comment.find(params[:id])
+ @comment.destroy
+
+ respond_to do |format|
+ format.html { redirect_to sites_url }
+ format.json { head :no_content }
+ end
+ end
+end
diff --git a/app/controllers/planet_controller.rb b/app/controllers/planet_controller.rb
index a8636bd..3af0790 100644
--- a/app/controllers/planet_controller.rb
+++ b/app/controllers/planet_controller.rb
@@ -29,5 +29,21 @@ def contact
# Método que define una acción vacía del controlador
def ejemplo
end
-
+ # Acción author
+ def author
+ end
+ # Método que define la búsqueda de palabras a encontrar en la aplicación
+ def search
+ if params[:busqueda].empty? or params[:busqueda].length < 3
+ @sites = []
+ @trips = []
+ else
+ @sites = Site.where("name like ? or description like ?", "%"+params[:busqueda]+"%", "%"+params[:busqueda]+"%")
+ @trips = Trip.where("name like ? or description like ?", "%"+params[:busqueda]+"%", "%"+params[:busqueda]+"%")
+ end
+ end
+
+ def table_of_contents
+ end
+
end
diff --git a/app/controllers/planet_controller.rb~ b/app/controllers/planet_controller.rb~
new file mode 100644
index 0000000..9eb2fe9
--- /dev/null
+++ b/app/controllers/planet_controller.rb~
@@ -0,0 +1,36 @@
+# PlanetController ilustra el uso de *RDoc*. La documentación de un proyecto en
+# genera en el directorio *proy/doc* en formato Web con
+# $proy> rake doc:app
+#
+# == Algunos comandos de formateo
+#
+# Tal y como muestra el subitulo anterior, este se define empezando la
+# línea con ==. En los títulos debe empezar por =.
+#
+# Un [ ... ] seguido de texto define una lista titulada, como aquí
+# [Clases, Módulos o Métodos] Se documentan con comentarios justo encima de sus definición, como aquí.
+#
+# Un * o - definen las entradas de una lista itemizada
+# * Un URL se define así email[mailto:pepe@ejemplo.com]
+# * o así {Pepe Rubio}[mailto:pepe@ejemplo.com]
+#
+# Un número o letra seguido de punto genera una lista númerada
+# 1. + permite generar *negrita*, igual que con HTML
+# 2. _ permite generar _cursiva_, igual que con HTML
+# 3. * permite generar letra de +teletipo+, igual que con HTML
+#
+class PlanetController < ApplicationController
+ # Método que define una acción vacía del controlador
+ def index
+ end
+ # Método que define una acción vacía del controlador
+ def contact
+ end
+ # Método que define una acción vacía del controlador
+ def ejemplo
+ end
+ # Acción author
+ def author
+ end
+
+end
diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb
index 57e0611..509af0b 100644
--- a/app/controllers/sites_controller.rb
+++ b/app/controllers/sites_controller.rb
@@ -1,3 +1,14 @@
+# Clase Ruby que hereda de +ApplicationController+.
+# Cuando la aplicación reciba una petición referente a sitios, la ruta determina qué controlador y acción realizar.
+# == Métodos para controlador sitios
+# * index
+# * show
+# * new
+# * edit
+# * create
+# * update
+# * destroy
+# * count_visita
class SitesController < ApplicationController
# authenticate_user! ejecuta acción solo si sesión existe
@@ -22,6 +33,7 @@ def index
# GET /sites/1.json
def show
@site = Site.find(params[:id])
+ @comment = @site.comments.build
respond_to do |format|
format.html # show.html.erb
@@ -88,9 +100,10 @@ def destroy
format.json { head :no_content }
end
end
-
- private
- def count_visita
+
+private
+# método cuenta visitas para gestionar el incremento de visitas a sitios
+def count_visita
@site.increment!(:visitas)
end
end
diff --git a/app/controllers/sites_controller.rb~ b/app/controllers/sites_controller.rb~
new file mode 100644
index 0000000..509af0b
--- /dev/null
+++ b/app/controllers/sites_controller.rb~
@@ -0,0 +1,109 @@
+# Clase Ruby que hereda de +ApplicationController+.
+# Cuando la aplicación reciba una petición referente a sitios, la ruta determina qué controlador y acción realizar.
+# == Métodos para controlador sitios
+# * index
+# * show
+# * new
+# * edit
+# * create
+# * update
+# * destroy
+# * count_visita
+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
+ def index
+ if params[:type_id].nil? or params[:type_id].empty?
+ @sites = Site.all # path: /types
+ else
+ @sites = Type.find(params[:type_id]).sites # path: /types/id/sites
+ end
+ 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])
+ @comment = @site.comments.build
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @site }
+ end
+ end
+
+ # GET /sites/new
+ # GET /sites/new.json
+ def new
+ @site = current_user.sites.build # crea sitio vacio asociado a current_user
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @site }
+ end
+ end
+
+ # GET /sites/1/edit
+ def edit
+ @site = current_user.sites.find(params[:id]) # busca solo en sitios asociados a current_user
+ end
+
+ # POST /sites
+ # POST /sites.json
+ def create
+ @site = current_user.sites.build(params[:site]) # Asigna solo si sitio asociado a current_user
+
+ respond_to do |format|
+ if @site.save
+ format.html { redirect_to @site, notice: 'Site was successfully created.' }
+ format.json { render json: @site, status: :created, location: @site }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @site.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /sites/1
+ # PUT /sites/1.json
+ def update
+ @site = current_user.sites.find(params[:id]) # busca solo en sitios asociados a current_user
+
+ respond_to do |format|
+ if @site.update_attributes(params[:site])
+ format.html { redirect_to @site, notice: 'Site was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @site.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /sites/1
+ # DELETE /sites/1.json
+ def destroy
+ @site = current_user.sites.find(params[:id]) # busca solo en sitios asociados a current_user
+ @site.destroy
+
+ respond_to do |format|
+ format.html { redirect_to sites_url }
+ format.json { head :no_content }
+ end
+ end
+
+private
+# método cuenta visitas para gestionar el incremento de visitas a sitios
+def count_visita
+ @site.increment!(:visitas)
+ end
+end
diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb
index 321f6e3..25e21bf 100644
--- a/app/controllers/trips_controller.rb
+++ b/app/controllers/trips_controller.rb
@@ -1,3 +1,13 @@
+# Clase Ruby que hereda de +ApplicationController+.
+# Cuando la aplicación reciba una petición referente a viajes, la ruta determina qué controlador y acción realizar.
+# == Métodos para controlador viajes
+# * index
+# * show
+# * new
+# * edit
+# * create
+# * update
+# * destroy
class TripsController < ApplicationController
# authenticate_user! ejecuta acción solo si sesión existe
diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rb
index da826f4..1a0545f 100644
--- a/app/controllers/types_controller.rb
+++ b/app/controllers/types_controller.rb
@@ -1,8 +1,18 @@
+# Clase Ruby que hereda de +ApplicationController+.
+# Cuando la aplicación reciba una petición referente a tipos, la ruta determina qué controlador y acción realizar
+# == Métodos para controlador tipos
+# * index
+# * show
+# * new
+# * edit
+# * create
+# * update
+# * destroy
class TypesController < ApplicationController
# GET /types
# GET /types.json
- def index
- @types = Type.all
+ def index
+ @types = Type.all #busca colección de recursos
respond_to do |format|
format.html # index.html.erb
@@ -13,7 +23,7 @@ def index
# GET /types/1
# GET /types/1.json
def show
- @type = Type.find(params[:id])
+ @type = Type.find(params[:id]) #busca elemento en la tabla
respond_to do |format|
format.html # show.html.erb
@@ -80,4 +90,13 @@ def destroy
format.json { head :no_content }
end
end
+
+ # ordered_index
+ def ordered_index
+ @types = Type.find(:all, :order => :name)
+ respond_to do |format|
+ format.html { render action: "index" }
+ format.json { render json: @types }
+ end
+ end
end
diff --git a/app/controllers/types_controller.rb~ b/app/controllers/types_controller.rb~
new file mode 100644
index 0000000..4aa7b77
--- /dev/null
+++ b/app/controllers/types_controller.rb~
@@ -0,0 +1,93 @@
+class TypesController < ApplicationController
+ # GET /types
+ # GET /types.json
+ def index
+ @types = Type.all #busca colección de recursos
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @types }
+ end
+ end
+
+ # GET /types/1
+ # GET /types/1.json
+ def show
+ @type = Type.find(params[:id]) #busca elemento en la tabla
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @type }
+ end
+ end
+
+ # GET /types/new
+ # GET /types/new.json
+ def new
+ @type = Type.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @type }
+ end
+ end
+
+ # GET /types/1/edit
+ def edit
+ @type = Type.find(params[:id])
+ end
+
+ # POST /types
+ # POST /types.json
+ def create
+ @type = Type.new(params[:type])
+
+ respond_to do |format|
+ if @type.save
+ format.html { redirect_to @type, notice: 'Type was successfully created.' }
+ format.json { render json: @type, status: :created, location: @type }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @type.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /types/1
+ # PUT /types/1.json
+ def update
+ @type = Type.find(params[:id])
+
+ respond_to do |format|
+ if @type.update_attributes(params[:type])
+ format.html { redirect_to @type, notice: 'Type was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @type.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /types/1
+ # DELETE /types/1.json
+ def destroy
+ @type = Type.find(params[:id])
+ @type.destroy
+
+ respond_to do |format|
+ format.html { redirect_to types_url }
+ format.json { head :no_content }
+ end
+ end
+end
+
+ # ordered_index
+ def ordered_index
+ @types = Type.find(:all, :order => :name)
+ respond_to do |format|
+ format.html { render action: "index" }
+ format.json { render json: @types }
+ end
+ end
+end
diff --git a/app/controllers/visits_controller.rb b/app/controllers/visits_controller.rb
index 5bd5366..6b4152c 100644
--- a/app/controllers/visits_controller.rb
+++ b/app/controllers/visits_controller.rb
@@ -1,3 +1,13 @@
+# Clase Ruby que hereda de +ApplicationController+.
+# Cuando la aplicación reciba una petición referente a visitas, la ruta determina qué controlador y acción realizar
+# == Métodos para controlador visitas
+# * index
+# * show
+# * new
+# * edit
+# * create
+# * update
+# * destroy
class VisitsController < ApplicationController
# GET /visits
# GET /visits.json
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index de6be79..4ad0de1 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,2 +1,4 @@
+#Rails genera método helper para facilitar la programación de vistas y controladores.
+# * En este caso para application.
module ApplicationHelper
end
diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb
new file mode 100644
index 0000000..9d80b98
--- /dev/null
+++ b/app/helpers/comments_helper.rb
@@ -0,0 +1,4 @@
+#Rails genera método helper para facilitar la programación de vistas y controladores.
+# * En este caso para comments.
+module CommentsHelper
+end
diff --git a/app/helpers/planet_helper.rb b/app/helpers/planet_helper.rb
index 5bbc197..9171c64 100644
--- a/app/helpers/planet_helper.rb
+++ b/app/helpers/planet_helper.rb
@@ -1,2 +1,4 @@
+#Rails genera método helper para facilitar la programación de vistas y controladores.
+# * En este caso para planet.
module PlanetHelper
end
diff --git a/app/helpers/sites_helper.rb b/app/helpers/sites_helper.rb
index 621069d..2a9d6af 100644
--- a/app/helpers/sites_helper.rb
+++ b/app/helpers/sites_helper.rb
@@ -1,2 +1,4 @@
+#Rails genera método helper para facilitar la programación de vistas y controladores.
+# * En este caso para sites.
module SitesHelper
end
diff --git a/app/helpers/trips_helper.rb b/app/helpers/trips_helper.rb
index 04f333d..44e7264 100644
--- a/app/helpers/trips_helper.rb
+++ b/app/helpers/trips_helper.rb
@@ -1,2 +1,4 @@
+#Rails genera método helper para facilitar la programación de vistas y controladores.
+# * En este caso para trips.
module TripsHelper
end
diff --git a/app/helpers/types_helper.rb b/app/helpers/types_helper.rb
index 40a2b9e..63024ea 100644
--- a/app/helpers/types_helper.rb
+++ b/app/helpers/types_helper.rb
@@ -1,2 +1,4 @@
+#Rails genera método helper para facilitar la programación de vistas y controladores.
+# * En este caso para types.
module TypesHelper
end
diff --git a/app/helpers/visits_helper.rb b/app/helpers/visits_helper.rb
index 8ce5f83..50b5a33 100644
--- a/app/helpers/visits_helper.rb
+++ b/app/helpers/visits_helper.rb
@@ -1,2 +1,4 @@
+#Rails genera método helper para facilitar la programación de vistas y controladores.
+# * En este caso para visits.
module VisitsHelper
end
diff --git a/app/models/comment.rb b/app/models/comment.rb
new file mode 100644
index 0000000..bb651ba
--- /dev/null
+++ b/app/models/comment.rb
@@ -0,0 +1,14 @@
+# Hereda lógica ORM de ActiveRecord::Base
+#
+# ORB (Object-Relational Mapping):
+# - patrón orientado a objetos de acceso a una BBDD donde los objetos son las filas de la BBDD
+#
+# == Modelo de Comment con relación uno-a-muchos:
+# * belongs_to: Comment referencia un objeto Site
+# * belongs_to: Comment referencia un objeto User
+class Comment < ActiveRecord::Base
+ belongs_to :site
+ belongs_to :user
+
+ validates :comment, :user_id, :site_id, :presence => true # campo obligatorio
+end
diff --git a/app/models/comment.rb~ b/app/models/comment.rb~
new file mode 100644
index 0000000..06aad18
--- /dev/null
+++ b/app/models/comment.rb~
@@ -0,0 +1,12 @@
+# Hereda lógica ORM de ActiveRecord::Base
+#
+# ORB (Object-Relational Mapping):
+# - patrón orientado a objetos de acceso a una BBDD donde los objetos son las filas de la BBDD
+#
+# == Modelo de Comment con relación uno-a-muchos:
+# * belongs_to: Comment referencia un objeto Site
+# * belongs_to: Comment referencia un objeto User
+class Comment < ActiveRecord::Base
+ belongs_to :site
+ belongs_to :user
+end
diff --git a/app/models/site.rb b/app/models/site.rb
index 2b2f99a..fadec12 100644
--- a/app/models/site.rb
+++ b/app/models/site.rb
@@ -1,8 +1,22 @@
+# Hereda lógica ORM de ActiveRecord::Base
+#
+# ORB (Object-Relational Mapping):
+# - patrón orientado a objetos de acceso a una BBDD donde los objetos son las filas de la BBDD
+#
+# == Modelo de Site con relación uno-a-muchos:
+# * belongs_to: Site referencia un objeto Type
+# * belongs_to: Site referencia un objeto User
+# * has_many: un Site referenciado por muchos Visit
+# * has_many: un Site referenciado por muchos Trip
+# * has_many: un Site referenciado por muchos Comment
class Site < ActiveRecord::Base
belongs_to :type
belongs_to :user
has_many :visits
has_many :trips, :through => :visits
+
+ has_many :comments
+
has_attached_file :image
diff --git a/app/models/site.rb~ b/app/models/site.rb~
new file mode 100644
index 0000000..2b2f99a
--- /dev/null
+++ b/app/models/site.rb~
@@ -0,0 +1,14 @@
+class Site < ActiveRecord::Base
+ belongs_to :type
+ belongs_to :user
+ has_many :visits
+ has_many :trips, :through => :visits
+ 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
+end
diff --git a/app/models/trip.rb b/app/models/trip.rb
index 4ff6d83..d93d3ca 100644
--- a/app/models/trip.rb
+++ b/app/models/trip.rb
@@ -1,3 +1,12 @@
+# Hereda lógica ORM de ActiveRecord::Base
+#
+# ORB (Object-Relational Mapping):
+# - patrón orientado a objetos de acceso a una BBDD donde los objetos son las filas de la BBDD
+#
+# == Modelo de Trip con relación uno-a-muchos:
+# * belongs_to: Trip referencia un objeto User
+# * has_many: un Trip referenciado por muchos Visit
+# * has_many: un Trip referenciado por muchos Site
class Trip < ActiveRecord::Base
belongs_to :user
has_many :visits
diff --git a/app/models/type.rb b/app/models/type.rb
index 2284d1f..15e57c4 100644
--- a/app/models/type.rb
+++ b/app/models/type.rb
@@ -1,3 +1,10 @@
+# Hereda lógica ORM de ActiveRecord::Base
+#
+# ORB (Object-Relational Mapping):
+# - patrón orientado a objetos de acceso a una BBDD donde los objetos son las filas de la BBDD
+#
+# == Modelo de Type con relación uno-a-muchos:
+# * has_many: un Type referenciado por muchos Site
class Type < ActiveRecord::Base
has_many :sites
diff --git a/app/models/user.rb b/app/models/user.rb
index 35b8159..8c02d53 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,7 +1,18 @@
+# Hereda lógica ORM de ActiveRecord::Base
+#
+# ORB (Object-Relational Mapping):
+# - patrón orientado a objetos de acceso a una BBDD donde los objetos son las filas de la BBDD
+#
+# == Modelo de Use con relación uno-a-muchos:
+# * has_many: un Use referenciado por muchos Site
+# * has_many: un Use referenciado por muchos Trip
+# * has_many: un Use referenciado por muchos Comment
class User < ActiveRecord::Base
has_many :sites
has_many :trips
+
+ has_many :comments
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
diff --git a/app/models/user.rb~ b/app/models/user.rb~
new file mode 100644
index 0000000..35b8159
--- /dev/null
+++ b/app/models/user.rb~
@@ -0,0 +1,15 @@
+class User < ActiveRecord::Base
+
+ has_many :sites
+ has_many :trips
+
+ # Include default devise modules. Others available are:
+ # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
+ devise :database_authenticatable, :registerable,
+ :recoverable, :rememberable, :trackable, :validatable
+
+ validates_presence_of :name
+
+ # Setup accessible (or protected) attributes for your model
+ attr_accessible :name, :email, :password, :password_confirmation, :remember_me
+end
diff --git a/app/models/visit.rb b/app/models/visit.rb
index 57546da..e00a0dd 100644
--- a/app/models/visit.rb
+++ b/app/models/visit.rb
@@ -1,3 +1,11 @@
+# Hereda lógica ORM de ActiveRecord::Base
+#
+# ORB (Object-Relational Mapping):
+# - patrón orientado a objetos de acceso a una BBDD donde los objetos son las filas de la BBDD
+#
+# == Modelo de Visit con relación uno-a-muchos:
+# * belongs_to: Visit referencia un objeto Trip
+# * belongs_to: Visit referencia un objeto Site
class Visit < ActiveRecord::Base
belongs_to :trip
belongs_to :site
diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb
new file mode 100644
index 0000000..f962c3f
--- /dev/null
+++ b/app/views/comments/_form.html.erb
@@ -0,0 +1,24 @@
+<%= form_for(@comment) do |f| %>
+ <% if @comment.errors.any? %>
+
+
<%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:
+
+
+ <% @comment.errors.full_messages.each do |msg| %>
+ - <%= msg %>
+ <% end %>
+
+
+ <% end %>
+
+
+ <%= f.label :comment %>
+ <%= f.text_area :comment %>
+
+
+<%= f.number_field :site_id, :value => @site.id, :hidden => true %>
+
+
+ <%= f.submit %>
+
+<% end %>
diff --git a/app/views/comments/_form.html.erb~ b/app/views/comments/_form.html.erb~
new file mode 100644
index 0000000..cf483f7
--- /dev/null
+++ b/app/views/comments/_form.html.erb~
@@ -0,0 +1,27 @@
+<%= form_for(@comment) do |f| %>
+ <% if @comment.errors.any? %>
+
+
<%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:
+
+
+ <% @comment.errors.full_messages.each do |msg| %>
+ - <%= msg %>
+ <% end %>
+
+
+ <% end %>
+
+
+ <%= f.label :comment %>
+ <%= f.text_area :comment %>
+
+
+
+ <%= f.label :site_id %>
+ <%= f.collection_select(:site_id, Site.find(:all, :order => :name), :id, :name) %>
+
+
+
+ <%= f.submit %>
+
+<% end %>
diff --git a/app/views/comments/edit.html.erb b/app/views/comments/edit.html.erb
new file mode 100644
index 0000000..12ea7f9
--- /dev/null
+++ b/app/views/comments/edit.html.erb
@@ -0,0 +1,6 @@
+Editing comment
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @comment %> |
+<%= link_to 'Back', comments_path %>
diff --git a/app/views/comments/index.html.erb b/app/views/comments/index.html.erb
new file mode 100644
index 0000000..774cbaf
--- /dev/null
+++ b/app/views/comments/index.html.erb
@@ -0,0 +1,28 @@
+Listing comments:
+
+
+
+ Comment |
+ User |
+ Site |
+ |
+ |
+ |
+
+
+<% @comments.each do |comment| %>
+
+ <%= comment.comment %> |
+ <%= comment.user.name if comment.user%> |
+ <%= comment.site.name %> |
+ <%= link_to 'Show', comment %> |
+<% if comment.user == current_user %>
+ <%= link_to 'Edit', edit_comment_path(comment) %> |
+ <%= link_to 'Destroy', comment, confirm: 'Are you sure?', method: :delete %> |
+<% end %>
+
+<% end %>
+
+
+
+
diff --git a/app/views/comments/index.html.erb~ b/app/views/comments/index.html.erb~
new file mode 100644
index 0000000..822b03a
--- /dev/null
+++ b/app/views/comments/index.html.erb~
@@ -0,0 +1,28 @@
+Listing comments del sitio:
+
+
+
+ Comment |
+ User |
+ Site |
+ |
+ |
+ |
+
+
+<% @comments.each do |comment| %>
+
+ <%= comment.comment %> |
+ <%= comment.user.name if comment.user%> |
+
+ <%= link_to 'Show', comment %> |
+<% if comment.user == current_user %>
+ <%= link_to 'Edit', edit_comment_path(comment) %> |
+ <%= link_to 'Destroy', comment, confirm: 'Are you sure?', method: :delete %> |
+<% end %>
+
+<% end %>
+
+
+
+
diff --git a/app/views/comments/new.html.erb b/app/views/comments/new.html.erb
new file mode 100644
index 0000000..07a754a
--- /dev/null
+++ b/app/views/comments/new.html.erb
@@ -0,0 +1,5 @@
+New comment
+
+<%= render 'form' %>
+
+<%= link_to 'Back', comments_path %>
diff --git a/app/views/comments/show.html.erb b/app/views/comments/show.html.erb
new file mode 100644
index 0000000..2698896
--- /dev/null
+++ b/app/views/comments/show.html.erb
@@ -0,0 +1,20 @@
+<%= notice %>
+
+
+ Comment:
+ <%= @comment.comment %>
+
+
+
+ User:
+ <%= @comment.user.name if @comment.user %>
+
+
+
+ Site:
+ <%= @comment.site.name %>
+
+
+<% if @comment.user == current_user %>
+<%= link_to 'Edit', edit_comment_path(@comment) %>
+<% end %>
diff --git a/app/views/comments/show.html.erb~ b/app/views/comments/show.html.erb~
new file mode 100644
index 0000000..2d79d5c
--- /dev/null
+++ b/app/views/comments/show.html.erb~
@@ -0,0 +1,20 @@
+<%= notice %>
+
+
+ Comment:
+ <%= @comment.comment %>
+
+
+
+ User:
+ <%= @comment.user.name %>
+
+
+
+ Site:
+ <%= @comment.site.name %>
+
+
+<% if @comment.user == current_user %>
+<%= link_to 'Edit', edit_comment_path(@comment) %>
+<% end %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index e4c9e36..4d576c2 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -5,8 +5,13 @@
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
-
-
+
+
+
@@ -14,7 +19,14 @@
<%= image_tag("logo3.png") %>
<%= @page_title || "Planet Travel Site" %>
-
<% if current_user %>
<%= link_to current_user.name,
edit_user_registration_path %> |
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
<% else %>
<%= link_to "Sign in", new_user_session_path %>
<% end %>
+
+ <% if current_user %>
+ <%= link_to current_user.name,
+ edit_user_registration_path %> |
+ <%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
+ <% else %>
+ <%= link_to "Sign in", new_user_session_path %>
+ <% end %>
@@ -22,14 +34,29 @@
<%= link_to "Home", planet_index_path %>
<%= link_to "Tipos", types_path %>
<%= link_to "Sitios", sites_path %>
- <%= link_to "Viajes", trips_path %>
+ <%= link_to "Viajes", trips_path %>
<%= link_to "Contact", planet_contact_path %>
<%= link_to "Sign up", new_user_registration_path unless current_user %>
+
Documentacion
+
+
+
-
<%= notice %>
<%= alert %>
+
<%= notice %>
<%= alert %>
+
+<%= link_to('Home', planet_index_path) + "|" + link_to('Contact', planet_contact_path) + "|" + link_to('Ejemplo', planet_ejemplo_path) + "|" + link_to('Author', planet_author_path) + "|" + link_to('Tipos', types_path) + "|" + link_to('Sitios', sites_path) + "|" + link_to('Tipos_ordenados', types_ordered_index_path) %>
<%= yield %>
+
+<%= link_to('Home', planet_index_path) + "|" + link_to('Contacts', planet_contact_path) + "|" + link_to('Ejemplo', planet_ejemplo_path) + "|" + link_to('Author', planet_author_path) + "|" + link_to('Tipos', types_path) + "|" + link_to('Sitios', sites_path) + "|" + link_to('Tipos_ordenados', types_ordered_index_path) %>
+
+
+
+