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 6 #33

Open
wants to merge 5 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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
/log/*.log
/tmp

# ignore al .DS_store files of MAC OSX
.DS_Store


# ignore paperclip installation files
public/system
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rvm:
- 1.9.2
11 changes: 4 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ gem 'rails', '3.2.2'
group :development do
gem 'sqlite3'
end

group :production do
gem 'pg'
end


gem 'devise'

# Gems used only for assets and not required
Expand All @@ -30,8 +24,11 @@ end

gem 'jquery-rails'
gem 'cleditor_rails'

gem 'paperclip'

gem 'pg'

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

Expand All @@ -45,4 +42,4 @@ gem 'paperclip'
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'
33 changes: 17 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
bcrypt-ruby (3.0.1)
bcrypt-ruby (3.0.1-x86-mingw32)
builder (3.0.0)
cleditor_rails (0.0.3)
cocaine (0.2.1)
Expand All @@ -39,7 +39,7 @@ GEM
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.2.0)
coffee-script-source (1.3.1)
devise (2.0.4)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
Expand All @@ -51,23 +51,24 @@ GEM
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
jquery-rails (2.0.1)
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.5)
json (1.6.6)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.1.0)
mime-types (1.18)
multi_json (1.3.2)
orm_adapter (0.0.7)
paperclip (2.4.5)
activerecord (>= 2.3.0)
activesupport (>= 2.3.2)
paperclip (3.0.2)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (>= 0.0.2)
mime-types
pg (0.13.2)
pg (0.13.2-x86-mingw32)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
Expand All @@ -94,30 +95,30 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
sass (3.1.15)
sass-rails (3.2.4)
sass (3.1.16)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
sqlite3 (1.3.6-x86-mingw32)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.32)
uglifier (1.2.3)
tzinfo (0.3.33)
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
warden (1.1.1)
rack (>= 1.0)

PLATFORMS
ruby
x86-mingw32

DEPENDENCIES
cleditor_rails
Expand Down
Binary file added app/assets/images/alfredo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/autorverdadero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/montserrat.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/prueba.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/pruebaII.png
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/
94 changes: 94 additions & 0 deletions app/controllers/comentarios_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
class ComentariosController < ApplicationController
# authenticate_user! ejecuta acción solo si sesión existe
before_filter :authenticate_user!, :except => [ :index, :show ]

# GET /comentarios
# GET /comentarios.json
def index
if params[:site_id].nil? or params[:site_id].empty?
@comentarios = Comentario.all # path: /sites
else
@comentarios = Site.find(params[:site_id]).comentarios # path: /sites/id/comentarios
end
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
@site = Site.find(params[:site_id])
@comentario = @site.comentarios.find(params[:id])
end

# POST /comentarios
# POST /comentarios.json
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 @site, notice: 'Comentario was successfully created.' }
else
format.html { render action: "edit" }
format.json { render json: @comentario.errors, status: :unprocessable_entity }
end
end
end

# PUT /comentarios/1
# PUT /comentarios/1.json
def update
@site = Site.find(params[:site_id])
@comentario = @site.comentarios.create(params[:comentario])
@comentario.user_id= current_user.id

respond_to do |format|
if @comentario.update_attributes(params[:comentario])
format.html { redirect_to @site, 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
@site = Site.find(params[:site_id])
@comentario = @site.comentarios.find(params[:id])
@comentario.destroy

respond_to do |format|
format.html { redirect_to site_path(@site) }
format.json { head :no_content }
end
end
end
21 changes: 17 additions & 4 deletions app/controllers/planet_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
class PlanetController < ApplicationController
#GET/planet/index
def index
end

#GET/planet/contact
def contact
end

#GET/planet/ejemplo
def ejemplo
end

end
#GET/planet/author
def author
end

def search
if params[:search].length >= 3
@sites = Site.where("name like ? OR description like ?", "%#{params[:search]}%", "%#{params[:search]}%")
@trips = Trip.where("name like ? OR description like ?", "%#{params[:search]}%", "%#{params[:search]}%")
else
render action: "errorSearch"
end
end

end
19 changes: 14 additions & 5 deletions app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class SitesController < ApplicationController

# authenticate_user! ejecuta acción solo si sesión existe
# authenticate_user! ejecuta acción solo si sesión existe
before_filter :authenticate_user!, :except => [ :index, :show ]
after_filter :count_visita, :only => :show
# para que solo se ejecute count_visita al realizar la accion show

# GET /sites
# GET /sites.json
# Obtiene todos los sitios y los renderiza en la misma vista
def index
if params[:type_id].nil? or params[:type_id].empty?
@sites = Site.all # path: /types
Expand All @@ -20,6 +21,7 @@ def index

# GET /sites/1
# GET /sites/1.json
# Muestra el siio cuyo id se pasa como parámetro.
def show
@site = Site.find(params[:id])

Expand All @@ -31,22 +33,25 @@ def show

# GET /sites/new
# GET /sites/new.json
# Muestra un formulario para añadir un nuevo sitio a la web.
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
# Muestra una vista para editar el sitio cuyo id se pasa como parámetro.
def edit
@site = current_user.sites.find(params[:id]) # busca solo en sitios asociados a current_user
end

# POST /sites
# POST /sites.json
# Muestra una vista con un mensaje de confirmación y el sitio creado.
def create
@site = current_user.sites.build(params[:site]) # Asigna solo si sitio asociado a current_user

Expand All @@ -63,6 +68,7 @@ def create

# PUT /sites/1
# PUT /sites/1.json
# Muestra una vista para editar los parámetros del sitio.
def update
@site = current_user.sites.find(params[:id]) # busca solo en sitios asociados a current_user

Expand All @@ -79,6 +85,7 @@ def update

# DELETE /sites/1
# DELETE /sites/1.json
# Elimina el sitio que se pasa como parámetro.
def destroy
@site = current_user.sites.find(params[:id]) # busca solo en sitios asociados a current_user
@site.destroy
Expand All @@ -88,9 +95,11 @@ def destroy
format.json { head :no_content }
end
end


# Aumenta las visitas de un sitio.
private
def count_visita
@site.increment!(:visitas)
end
end

end
12 changes: 12 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_types
# GET /types/ordered_types.json
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


# GET /types/1
# GET /types/1.json
def show
Expand Down
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
7 changes: 7 additions & 0 deletions app/models/comentario.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Comentario < ActiveRecord::Base
belongs_to :site
belongs_to :user

attr_protected :user_id
validates :coment, :presence => true # campo obligatorio
end
1 change: 1 addition & 0 deletions app/models/site.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Site < ActiveRecord::Base
belongs_to :type
belongs_to :user
has_many :comentarios
has_many :visits
has_many :trips, :through => :visits
has_attached_file :image
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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
Loading