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/app/assets/images/foto.jpg b/app/assets/images/foto.jpg new file mode 100755 index 0000000..60f27f1 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/controllers/comentarios_controller.rb b/app/controllers/comentarios_controller.rb new file mode 100644 index 0000000..9ae7666 --- /dev/null +++ b/app/controllers/comentarios_controller.rb @@ -0,0 +1,83 @@ +class ComentariosController < ApplicationController + # 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 diff --git a/app/controllers/planet_controller.rb b/app/controllers/planet_controller.rb index a8636bd..c98ce96 100644 --- a/app/controllers/planet_controller.rb +++ b/app/controllers/planet_controller.rb @@ -30,4 +30,17 @@ def contact def ejemplo end + def author + end + + 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: "menosdetres" + end + end + + end diff --git a/app/controllers/planet_controller.rb~ b/app/controllers/planet_controller.rb~ new file mode 100644 index 0000000..9637e74 --- /dev/null +++ b/app/controllers/planet_controller.rb~ @@ -0,0 +1,37 @@ +# 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 + + def author + end + + +end diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rb index da826f4..2186e4e 100644 --- a/app/controllers/types_controller.rb +++ b/app/controllers/types_controller.rb @@ -10,6 +10,18 @@ def index end end + # GET /types/ordered_index + # GET /types/ordered_index.json + def ordered_index + @types = Type.find(:all,:order => :name) + + respond_to do |format| + format.html # ordered_index.html.erb + format.json { render json: @type } + end + + end + # GET /types/1 # GET /types/1.json def show @@ -21,6 +33,8 @@ def show end end + + # GET /types/new # GET /types/new.json def new diff --git a/app/controllers/types_controller.rb~ b/app/controllers/types_controller.rb~ new file mode 100644 index 0000000..7c668e6 --- /dev/null +++ b/app/controllers/types_controller.rb~ @@ -0,0 +1,97 @@ +class TypesController < ApplicationController + # GET /types + # GET /types.json + def index + @types = Type.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @types } + end + end + + # GET /types/ordered_index + # GET /types/ordered_index.json + def ordered_index + @type = Type.find(:all,:order => :name) + + respond_to do |format| + format.html # ordered_index.html.erb + format.json { render json: @type } + end + + end + + # GET /types/1 + # GET /types/1.json + def show + @type = Type.find(params[:id]) + + 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 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..14d1412 --- /dev/null +++ b/app/models/comentario.rb @@ -0,0 +1,6 @@ +class Comentario < ActiveRecord::Base + +belongs_to :user +belongs_to :site + +end diff --git a/app/models/comentario.rb~ b/app/models/comentario.rb~ new file mode 100644 index 0000000..922c311 --- /dev/null +++ b/app/models/comentario.rb~ @@ -0,0 +1,6 @@ +class Comentario < ActiveRecord::Base + +belong_to :user +belong_to :site + +end diff --git a/app/models/site.rb b/app/models/site.rb index 2b2f99a..66b6428 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -2,6 +2,7 @@ class Site < ActiveRecord::Base belongs_to :type belongs_to :user has_many :visits + has_many :comentarios has_many :trips, :through => :visits has_attached_file :image diff --git a/app/models/site.rb~ b/app/models/site.rb~ new file mode 100644 index 0000000..66b6428 --- /dev/null +++ b/app/models/site.rb~ @@ -0,0 +1,15 @@ +class Site < ActiveRecord::Base + belongs_to :type + belongs_to :user + has_many :visits + has_many :comentarios + 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/user.rb b/app/models/user.rb index 35b8159..6b7d746 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,6 +2,8 @@ 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/user.rb~ b/app/models/user.rb~ new file mode 100644 index 0000000..1a1d0f3 --- /dev/null +++ b/app/models/user.rb~ @@ -0,0 +1,17 @@ +class User < ActiveRecord::Base + + has_many :site + has_many :trips + has_many :comentarios + + + # 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/views/comentarios/_form.html.erb b/app/views/comentarios/_form.html.erb new file mode 100644 index 0000000..7f1faf7 --- /dev/null +++ b/app/views/comentarios/_form.html.erb @@ -0,0 +1,26 @@ +<%= 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 %> + |
+
| Coment | +User | +Site | ++ | + | + |
|---|---|---|---|---|---|
| <%= comentario.coment %> | +<%= comentario.user %> | +<%= comentario.site %> | +<%= link_to 'Show', comentario %> | +<%= link_to 'Edit', edit_comentario_path(comentario) if comentario.user==current_user %> | +<%= link_to 'Destroy', comentario, confirm: 'Are you sure?', method: :delete if comentario.user==current_user %> | +
<%= notice %>
+ ++ Coment: + <%= @comentario.coment %> +
+ ++ User: + <%= @comentario.user_id %> +
+ ++ Site: + <%= @comentario.site_id %> +
+ + +<%= link_to 'Edit', edit_comentario_path(@comentario) %> | +<%= link_to 'Back', comentarios_path %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e4c9e36..2b57459 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,7 +18,18 @@