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 8 Completa: Roberto Fuentes Martinez #57

Open
wants to merge 11 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
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/
83 changes: 83 additions & 0 deletions app/controllers/comentarios_controller.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions app/controllers/planet_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 37 additions & 0 deletions app/controllers/planet_controller.rb~
Original file line number Diff line number Diff line change
@@ -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:[email protected]]
# * o así {Pepe Rubio}[mailto:[email protected]]
#
# Un número o letra seguido de punto genera una lista númerada
# 1. + permite generar *negrita*, igual que <b>con HTML</b>
# 2. _ permite generar _cursiva_, igual que <em>con HTML</em>
# 3. * permite generar letra de +teletipo+, igual que <tt> con HTML</tt>
#
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
14 changes: 14 additions & 0 deletions app/controllers/types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,6 +33,8 @@ def show
end
end



# GET /types/new
# GET /types/new.json
def new
Expand Down
97 changes: 97 additions & 0 deletions app/controllers/types_controller.rb~
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/helpers/comentarios_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ComentariosHelper
end
6 changes: 6 additions & 0 deletions app/models/comentario.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Comentario < ActiveRecord::Base

belongs_to :user
belongs_to :site

end
6 changes: 6 additions & 0 deletions app/models/comentario.rb~
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Comentario < ActiveRecord::Base

belong_to :user
belong_to :site

end
1 change: 1 addition & 0 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions app/models/site.rb~
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions app/models/user.rb~
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions app/views/comentarios/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%= form_for(@comentario) do |f| %>
<% if @comentario.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@comentario.errors.count, "error") %> prohibited this comentario from being saved:</h2>

<ul>
<% @comentario.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :coment %><br />
<%= f.text_area :coment, :maxlength => 240,:rows => 6 %>
</div>

<div class="field">
<%= f.label :site_id %><br />
<%= f.collection_select(:site_id, Site.find(:all, :order => :name), :id, :name) %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Loading