diff --git a/.gitignore b/.gitignore index 4a4d70e..c0f9050 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,11 @@ # ignore al .DS_store files of MAC OSX .DS_Store +<<<<<<< HEAD +*~ +======= # ignore paperclip installation files public/system -.project \ No newline at end of file +.project +>>>>>>> upstream/master diff --git a/Gemfile b/Gemfile index b0be4dd..4a1783b 100644 --- a/Gemfile +++ b/Gemfile @@ -46,3 +46,6 @@ gem 'paperclip' # To use debugger # gem 'ruby-debug19', :require => 'ruby-debug' + +gem 'execjs' +gem 'therubyracer' diff --git a/Gemfile.lock b/Gemfile.lock index 3b96e7c..9c49172 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -55,11 +55,12 @@ 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.17.2) + mime-types (1.18) multi_json (1.1.0) orm_adapter (0.0.7) paperclip (2.4.5) @@ -95,7 +96,7 @@ GEM rdoc (3.12) json (~> 1.4) sass (3.1.15) - sass-rails (3.2.4) + sass-rails (3.2.5) railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) @@ -104,6 +105,8 @@ GEM rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.5) + therubyracer (0.9.10) + libv8 (~> 3.3.10) thor (0.14.6) tilt (1.3.3) treetop (1.4.10) @@ -123,10 +126,12 @@ DEPENDENCIES cleditor_rails coffee-rails (~> 3.2.1) devise + execjs jquery-rails paperclip pg rails (= 3.2.2) sass-rails (~> 3.2.3) sqlite3 + therubyracer uglifier (>= 1.0.3) diff --git a/README b/README new file mode 100644 index 0000000..c8f68c2 --- /dev/null +++ b/README @@ -0,0 +1 @@ +All that's missing is the fork. Heh. \ No newline at end of file diff --git a/app/assets/images/fran.jpg b/app/assets/images/fran.jpg new file mode 100644 index 0000000..fdfda70 Binary files /dev/null and b/app/assets/images/fran.jpg differ diff --git a/app/assets/images/jq6.jpg b/app/assets/images/jq6.jpg new file mode 100644 index 0000000..2dceac4 Binary files /dev/null and b/app/assets/images/jq6.jpg differ diff --git a/app/assets/images/mandi.png b/app/assets/images/mandi.png new file mode 100644 index 0000000..4e990ff Binary files /dev/null and b/app/assets/images/mandi.png 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..e730912 --- /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/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 0000000..dfb5f63 --- /dev/null +++ b/app/controllers/comments_controller.rb @@ -0,0 +1,83 @@ +class CommentsController < ApplicationController + # GET /comments + # GET /comments.json + def index + @comments = Comment.all + + 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 diff --git a/app/controllers/planet_controller.rb b/app/controllers/planet_controller.rb index be7ac0a..7e66568 100644 --- a/app/controllers/planet_controller.rb +++ b/app/controllers/planet_controller.rb @@ -7,5 +7,8 @@ def contact def ejemplo end + + def author + end end diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index 57e0611..06ceb6e 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -22,7 +22,8 @@ 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.json { render json: @site } @@ -93,4 +94,5 @@ def destroy def count_visita @site.increment!(:visitas) end + end diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rb index da826f4..f21a38b 100644 --- a/app/controllers/types_controller.rb +++ b/app/controllers/types_controller.rb @@ -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 diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb new file mode 100644 index 0000000..0ec9ca5 --- /dev/null +++ b/app/helpers/comments_helper.rb @@ -0,0 +1,2 @@ +module CommentsHelper +end diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..240619b --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,4 @@ +class Comment < ActiveRecord::Base + belongs_to :user + belongs_to :site +end diff --git a/app/models/site.rb b/app/models/site.rb index 2b2f99a..fd5633c 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -4,7 +4,7 @@ class Site < ActiveRecord::Base has_many :visits has_many :trips, :through => :visits has_attached_file :image - + has_many :comments # Debe estar protegido para evitar accesos indeseados attr_protected :user_id diff --git a/app/models/user.rb b/app/models/user.rb index 35b8159..6d15d11 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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, diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb new file mode 100644 index 0000000..0f66de0 --- /dev/null +++ b/app/views/comments/_form.html.erb @@ -0,0 +1,29 @@ +<%= form_for(@comment) do |f| %> + <% if @comment.errors.any? %> +
+

<%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :coment %>
+ <%= f.text_field :coment %> +
+
+ <%= f.label :user_id %>
+ <%= f.number_field :user_id %> +
+
+ <%= f.label :site_id %>
+ <%= f.number_field :site_id %> +
+
+ <%= 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..6de5f95 --- /dev/null +++ b/app/views/comments/index.html.erb @@ -0,0 +1,27 @@ +

Listing comments

+ + + + + + + + + + + +<% @comments.each do |comment| %> + + + + + + + + +<% end %> +
ComentUserSite
<%= comment.coment %><%= comment.user_id %><%= comment.site_id %><%= link_to 'Show', comment %><%= link_to 'Edit', edit_comment_path(comment) if comment.user_id == current_user.id %><%= link_to 'Destroy', comment, confirm: 'Are you sure?', method: :delete if comment.user_id == current_user.id %>
+ +
+ +<%= link_to 'New Comment', new_comment_path %> 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..8aacb2a --- /dev/null +++ b/app/views/comments/show.html.erb @@ -0,0 +1,20 @@ +

<%= notice %>

+ +

+ Coment: + <%= @comment.coment %> +

+ +

+ User: + <%= @comment.user_id %> +

+ +

+ Site: + <%= @comment.site_id %> +

+ + +<%= link_to 'Edit', edit_comment_path(@comment) %> | +<%= link_to 'Back', comments_path %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 82edd70..5fbc3a3 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,14 @@ - \ No newline at end of file + diff --git a/app/views/planet/author.html.erb b/app/views/planet/author.html.erb new file mode 100644 index 0000000..f8cfb3e --- /dev/null +++ b/app/views/planet/author.html.erb @@ -0,0 +1,16 @@ +

Author

+ +

+<%= image_tag('fran.jpg') %>
+Name: Francisco Ayala Serrano
+Address: Calle Falsa 123, 28001 Madrid
+e-mail
+Curriculum: estudiante de Ingeniería de Telecomunicación. +

+

+<%= image_tag('mandi.png') %>
+Name: Jose Francisco Barea López
+Address: Calle Falsa 123, 28001 Madrid
+e-mail
+Curriculum: estudiante de Ingeniería de Telecomunicación y pensador. +

diff --git a/app/views/sites/index.html.erb b/app/views/sites/index.html.erb index b8e4cae..9d7327b 100644 --- a/app/views/sites/index.html.erb +++ b/app/views/sites/index.html.erb @@ -19,11 +19,16 @@ <%= link_to 'Show', site %>
- <% if site.user == current_user %> <%= link_to 'Edit', edit_site_path(site) %>
+ <% if site.user == current_user %> + <%= link_to 'Edit', edit_site_path(site) %>
<%= link_to 'Destroy', site, :confirm => 'Are you sure?', :method => :delete %> - <% end %> + <% end %>
+ <% if site.comments.exists? %> + <%= link_to 'Comentarios', site_comments_path(site) %> + <% end %> + <% end %> @@ -31,4 +36,4 @@
-<%= link_to 'New site', new_site_path %> \ No newline at end of file +<%= link_to 'New site', new_site_path %> diff --git a/app/views/sites/show.html.erb b/app/views/sites/show.html.erb index 01a5417..0b751fd 100644 --- a/app/views/sites/show.html.erb +++ b/app/views/sites/show.html.erb @@ -7,13 +7,42 @@

<%= @site.name %>

<%=sanitize @site.description %>

+ +

Autor: + <%= @site.user.name if @site.user %>

-

Autor: <%= @site.user.name if @site.user %>

+

Comentarios

+ <% if @site.comments.exists? %> + <% @site.comments.each do |comment| %> +

<%= comment.user_id %> + : + <%= comment.coment %> + <% if comment.user_id == current_user.id %> +
<%= link_to 'Edit', edit_comment_path(comment) %> + <%= link_to 'Destroy', comment, :confirm => 'Are you sure?', :method => :delete %> + <% end %>

+ <% end %> + <% end %> + +

Añadir un comentario:

+ <% if current_user %> + <%= form_for @comments do |f| %> + <%= f.number_field :site_id, :value => @site.id, :hidden => true %> + <%= f.number_field :user_id, :value => current_user.id, :hidden => true %> + <%= f.text_field :coment %>
+ <%= f.submit "Añadir comentario" %> + <% end %> + <% else %> + <%= link_to "Ingrese", new_user_session_path %> para comentar: + <% end %>
Visitas: <%= @site.visitas %>

-<% if @site.user == current_user %> <%= link_to 'Edit', edit_site_path(@site) %> | <% end %> <%= link_to 'Back', sites_path %> +<% if @site.user == current_user %> + <%= link_to 'Edit', edit_site_path(@site) %> | +<% end %> +<%= link_to 'Back', sites_path %> diff --git a/app/views/types/index.html.erb b/app/views/types/index.html.erb index e761359..67a56b6 100644 --- a/app/views/types/index.html.erb +++ b/app/views/types/index.html.erb @@ -23,7 +23,7 @@ <% end %> - +
diff --git a/app/views/types/ordered_index.html.erb b/app/views/types/ordered_index.html.erb new file mode 100644 index 0000000..8e08eef --- /dev/null +++ b/app/views/types/ordered_index.html.erb @@ -0,0 +1,27 @@ +

Listing types

+ + + + + + + + + + + +<% @types.each do |type| %> + + + + + + + + +<% end %> +
NameDescriptionLast Modified
<%= type.name %><%= type.description %><%= type.updated_at %><%= link_to 'Show', type %><%= link_to 'Edit', edit_type_path(type) %><%= link_to 'Destroy', type, confirm: 'Are you sure?', method: :delete %>
+ +
+ +<%= link_to 'New Type', new_type_path %> diff --git a/app/views/types/show.html.erb b/app/views/types/show.html.erb index 98b32e7..79a748c 100644 --- a/app/views/types/show.html.erb +++ b/app/views/types/show.html.erb @@ -10,6 +10,10 @@ <%= @type.description %>

+

+ Last Modified: + <%= @type.updated_at %> +

<%= link_to 'Edit', edit_type_path(@type) %> | <%= link_to 'Back', types_path %> diff --git a/config/routes.rb b/config/routes.rb index 29d3c86..45f1143 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,16 @@ Planet::Application.routes.draw do + resources :comments + resources :visits resources :trips devise_for :users - resources :sites + resources :sites do + resources :comments + end resources :types do # Rutas anidadas /types/id/sites..., resources :sites, :only => [ :index ] # Restringe a acción “index” @@ -17,6 +21,14 @@ get "planet/contact" get "planet/ejemplo" + + get "planet/author" + + get "types/index" + + get "types/ordered_index" + + #resources :types # The priority is based upon order of creation: # first created -> highest priority. diff --git a/db/migrate/20120415104000_create_comments.rb b/db/migrate/20120415104000_create_comments.rb new file mode 100644 index 0000000..b2c7aee --- /dev/null +++ b/db/migrate/20120415104000_create_comments.rb @@ -0,0 +1,11 @@ +class CreateComments < ActiveRecord::Migration + def change + create_table :comments do |t| + t.string :coment + t.integer :user_id + t.integer :site_id + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index e6aa66f..99e5852 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,15 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120411160519) do +ActiveRecord::Schema.define(:version => 20120415104000) do + + create_table "comments", :force => true do |t| + t.string "coment" + t.integer "user_id" + t.integer "site_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end create_table "sites", :force => true do |t| t.string "name" diff --git a/forkit.gif b/forkit.gif new file mode 100644 index 0000000..a6a48b3 Binary files /dev/null and b/forkit.gif differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..79eddc4 --- /dev/null +++ b/index.html @@ -0,0 +1,63 @@ + + + + + + + Spoon-Knife + + + + + + + + + +

+ Fork me? No, fork you! +

+ + + diff --git a/test/fixtures/comments.yml b/test/fixtures/comments.yml new file mode 100644 index 0000000..e7e2ac9 --- /dev/null +++ b/test/fixtures/comments.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + coment: MyString + user_id: 1 + site_id: 1 + +two: + coment: MyString + user_id: 1 + site_id: 1 diff --git a/test/functional/comments_controller_test.rb b/test/functional/comments_controller_test.rb new file mode 100644 index 0000000..b2b500c --- /dev/null +++ b/test/functional/comments_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class CommentsControllerTest < ActionController::TestCase + setup do + @comment = comments(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:comments) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create comment" do + assert_difference('Comment.count') do + post :create, comment: @comment.attributes + end + + assert_redirected_to comment_path(assigns(:comment)) + end + + test "should show comment" do + get :show, id: @comment + assert_response :success + end + + test "should get edit" do + get :edit, id: @comment + assert_response :success + end + + test "should update comment" do + put :update, id: @comment, comment: @comment.attributes + assert_redirected_to comment_path(assigns(:comment)) + end + + test "should destroy comment" do + assert_difference('Comment.count', -1) do + delete :destroy, id: @comment + end + + assert_redirected_to comments_path + end +end diff --git a/test/functional/planet_controller_test.rb b/test/functional/planet_controller_test.rb index 88229e0..df4bf12 100644 --- a/test/functional/planet_controller_test.rb +++ b/test/functional/planet_controller_test.rb @@ -11,4 +11,13 @@ class PlanetControllerTest < ActionController::TestCase assert_response :success end + test "should get example" do + get :ejemplo + assert_response :success + end + + test "should get author" do + get :author + assert_response :success + end end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb new file mode 100644 index 0000000..b6d6131 --- /dev/null +++ b/test/unit/comment_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CommentTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/helpers/comments_helper_test.rb b/test/unit/helpers/comments_helper_test.rb new file mode 100644 index 0000000..2518c16 --- /dev/null +++ b/test/unit/helpers/comments_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class CommentsHelperTest < ActionView::TestCase +end