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 #59

Open
wants to merge 19 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: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

# ignore al .DS_store files of MAC OSX
.DS_Store
<<<<<<< HEAD
*~
=======

# ignore paperclip installation files
public/system
.project
.project
>>>>>>> upstream/master
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ gem 'paperclip'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

gem 'json', '1.6.5'

gem 'execjs'
gem 'therubyracer'
gem 'json', '1.6.5'
9 changes: 7 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ GEM
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.5)
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)
Expand Down Expand Up @@ -104,7 +105,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)
Expand All @@ -124,11 +127,13 @@ 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)
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All that's missing is the fork. Heh.
Binary file added app/assets/images/fran.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/jq6.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/mandi.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/comments.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/
7 changes: 7 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@
*= require cleditor
*= require_tree .
*/

html, body {
width: 100%; height: 100%;
}
#imagen{
max-width: 70%;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/comments.css.scss
Original file line number Diff line number Diff line change
@@ -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/
1 change: 1 addition & 0 deletions app/assets/stylesheets/sites.css.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Place all the styles related to the sites controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

3 changes: 3 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
class ApplicationController < ActionController::Base
protect_from_forgery

def doc
end
end
87 changes: 87 additions & 0 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
class CommentsController < ApplicationController
# GET /comments
# GET /comments.json
def index
if params[:site_id].nil? or params[:site_id].empty?
@comments = Comment.all
else
@comments = Site.find(params[:site_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 = Comment.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @comment }
end
end

# GET /comments/1/edit
def edit
@comment = Comment.find(params[:id])
end

# POST /comments
# POST /comments.json
def create
@comment = Comment.new(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 = Comment.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
14 changes: 13 additions & 1 deletion app/controllers/planet_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,17 @@ def contact
# Método que define una acción vacía del controlador
def ejemplo
end


def author
end
# Método que define la acción búsqueda del controlador
def search
if params[:buscar].length >= 3
@sites = Site.where("name like ? OR description like ?", "%#{params[:buscar]}%", "%#{params[:buscar]}%")
@trips = Trip.where("name like ? OR description like ?", "%#{params[:buscar]}%", "%#{params[:buscar]}%")
else
render action: "menosdetres"
end
end

end
4 changes: 3 additions & 1 deletion app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ def index
# GET /sites/1.json
def show
@site = Site.find(params[:id])

@comments = @site.comments.build

respond_to do |format|
format.html # show.html.erb
format.js
format.json { render json: @site }
end
end
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,13 @@ def destroy
format.json { head :no_content }
end
end

def ordered_index
@types = Type.order(:name)

respond_to do |format|
format.html # index.html.erb
format.json { render json: @types }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/comments_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CommentsHelper
end
7 changes: 7 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :site

validates :user_id, :presence => true
#attr_protected :user_id
end
9 changes: 7 additions & 2 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ class Site < ActiveRecord::Base
belongs_to :user
has_many :visits
has_many :trips, :through => :visits
has_attached_file :image

has_attached_file :image,
:styles => {
:thumb => "50x50",
:small => "150x150",
:medium => "200x200"
}
has_many :comments

# Debe estar protegido para evitar accesos indeseados
attr_protected :user_id
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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
devise :database_authenticatable, :registerable,
Expand Down
22 changes: 22 additions & 0 deletions app/views/comments/_comment.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div id="site_list">

<table>
<td class="list_description">
<dl>
<dt><%= comment.user_id %></dt>
<dd></p><%= truncate(strip_tags(comment.coment),
:length => 240) %></dd>
</dl>
</td>

<td class="list_actions">
<% if comment.user == current_user %>
<%= link_to 'Edit', edit_site_comment_path(comment.site, comment) %><br/>
<%= link_to 'Destroy', [comment.site, comment],
:confirm => 'Are you sure?',
:method => :delete %>
</td>
</tr>
<% end %>
</table>
</div>
29 changes: 29 additions & 0 deletions app/views/comments/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%= form_for(@comment) do |f| %>
<% if @comment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>

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

<div class="field">
<%= f.label :coment %><br />
<%= f.text_field :coment %>
</div>
<div class="field">
<%= f.label :user_id, :hidden => true %>
<%= f.number_field :user_id, :value => current_user.id, :hidden => true %>
</div>
<div class="field">
<%= f.label :site_id, :hidden => true %>
<%= f.number_field :site_id, :hidden => true %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/comments/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing comment</h1>

<%= render 'form' %>

<%= link_to 'Show', @comment %> |
<%= link_to 'Back', site_path(@comment.site) %>
29 changes: 29 additions & 0 deletions app/views/comments/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<h1>Listing comments</h1>

<table>
<tr>
<th>Coment</th>
<th>User</th>
<th>Site</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @comments.each do |comment| %>
<tr>
<td><%= comment.coment %></td>
<td><%= comment.user_id %></td>
<td><%= comment.site_id %></td>
<td><%= link_to 'Show', comment %></td>
<% if comment.user == current_user %>
<td><%= link_to 'Edit', edit_comment_path(comment) %></td>
<td><%= link_to 'Destroy', comment, confirm: 'Are you sure?', method: :delete %></td>
<% end %>
</tr>
<% end %>
</table>

<br />


5 changes: 5 additions & 0 deletions app/views/comments/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New comment</h1>

<%= render 'form' %>

<%= link_to 'Back', comments_path %>
20 changes: 20 additions & 0 deletions app/views/comments/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<p id="notice"><%= notice %></p>

<p>
<b>Coment:</b>
<%= @comment.coment %>
</p>

<p>
<b>User:</b>
<%= @comment.user_id %>
</p>

<p>
<b>Site:</b>
<%= @comment.site_id %>
</p>


<%= link_to 'Edit', edit_comment_path(@comment) %> |
<%= link_to 'Back', site_path(@comment.site) %>
Loading