Skip to content
Browse files

Fixed @posts in votes_controller issue

  • Loading branch information...
1 parent b497d25 commit 4b8dbcc024ab3c852f85f49b870cd36228d534c2 @Apechai committed Nov 28, 2011
View
4 Gemfile
@@ -5,10 +5,6 @@ gem 'rails', '3.1.1'
gem 'sqlite3', '1.3.4', :group => :development
-group :production do
- gem "pg"
-end
-
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
View
235 Gemfile.lock
@@ -0,0 +1,235 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.1.1)
+ actionpack (= 3.1.1)
+ mail (~> 2.3.0)
+ actionpack (3.1.1)
+ activemodel (= 3.1.1)
+ activesupport (= 3.1.1)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.2)
+ rack-cache (~> 1.1)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.2)
+ activemodel (3.1.1)
+ activesupport (= 3.1.1)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.1)
+ activemodel (= 3.1.1)
+ activesupport (= 3.1.1)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.1)
+ activemodel (= 3.1.1)
+ activesupport (= 3.1.1)
+ activesupport (3.1.1)
+ multi_json (~> 1.0)
+ addressable (2.2.6)
+ arel (2.2.1)
+ bcrypt-ruby (3.0.1)
+ builder (3.0.0)
+ capybara (1.1.2)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.2.2)
+ ffi (~> 1.0.6)
+ coffee-rails (3.1.1)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.1.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.1.3)
+ cucumber (1.1.3)
+ builder (>= 2.1.2)
+ diff-lcs (>= 1.1.2)
+ gherkin (~> 2.6.7)
+ json (>= 1.4.6)
+ term-ansicolor (>= 1.0.6)
+ cucumber-rails (1.2.0)
+ capybara (>= 1.1.1)
+ cucumber (>= 1.1.1)
+ nokogiri (>= 1.5.0)
+ database_cleaner (0.7.0)
+ devise (1.5.1)
+ bcrypt-ruby (~> 3.0)
+ orm_adapter (~> 0.0.3)
+ warden (~> 1.1)
+ diff-lcs (1.1.3)
+ em-websocket (0.3.5)
+ addressable (>= 2.1.1)
+ eventmachine (>= 0.12.9)
+ erubis (2.7.0)
+ eventmachine (0.12.10)
+ execjs (1.2.9)
+ multi_json (~> 1.0)
+ factory_girl (2.3.0)
+ activesupport
+ factory_girl_rails (1.4.0)
+ factory_girl (~> 2.3.0)
+ railties (>= 3.0.0)
+ ffi (1.0.11)
+ gherkin (2.6.8)
+ json (>= 1.4.6)
+ growl (1.0.3)
+ guard (0.8.8)
+ thor (~> 0.14.6)
+ guard-bundler (0.1.3)
+ bundler (>= 1.0.0)
+ guard (>= 0.2.2)
+ guard-cucumber (0.7.4)
+ cucumber (>= 0.10)
+ guard (>= 0.8.3)
+ guard-livereload (0.3.1)
+ em-websocket (>= 0.2.0)
+ guard (>= 0.4.0)
+ multi_json (~> 1.0.3)
+ guard-rails (0.0.3)
+ guard (>= 0.2.2)
+ guard-rspec (0.5.5)
+ guard (>= 0.8.4)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.18)
+ railties (~> 3.0)
+ thor (~> 0.14)
+ json (1.6.1)
+ json_pure (1.6.1)
+ launchy (2.0.5)
+ addressable (~> 2.2.6)
+ less (2.0.7)
+ therubyracer (~> 0.9.2)
+ less-rails (2.1.0)
+ actionpack (~> 3.1.1)
+ less (~> 2.0.7)
+ libv8 (3.3.10.4)
+ mail (2.3.0)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.17.2)
+ multi_json (1.0.3)
+ nokogiri (1.5.0)
+ orm_adapter (0.0.5)
+ polyglot (0.3.3)
+ rack (1.3.5)
+ rack-cache (1.1)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.1)
+ actionmailer (= 3.1.1)
+ actionpack (= 3.1.1)
+ activerecord (= 3.1.1)
+ activeresource (= 3.1.1)
+ activesupport (= 3.1.1)
+ bundler (~> 1.0)
+ railties (= 3.1.1)
+ rails-footnotes (3.7.5)
+ rails (>= 3.0.0)
+ railties (3.1.1)
+ actionpack (= 3.1.1)
+ activesupport (= 3.1.1)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rb-fsevent (0.4.3.1)
+ rdoc (3.11)
+ json (~> 1.4)
+ rspec (2.8.0.rc1)
+ rspec-core (= 2.8.0.rc1)
+ rspec-expectations (= 2.8.0.rc1)
+ rspec-mocks (= 2.8.0.rc1)
+ rspec-core (2.8.0.rc1)
+ rspec-expectations (2.8.0.rc1)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0.rc1)
+ rspec-rails (2.8.0.rc1)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (= 2.8.0.rc1)
+ rubyzip (0.9.4)
+ sass (3.1.10)
+ sass-rails (3.1.5)
+ actionpack (~> 3.1.0)
+ railties (~> 3.1.0)
+ sass (~> 3.1.10)
+ tilt (~> 1.3.2)
+ selenium-webdriver (2.13.0)
+ childprocess (>= 0.2.1)
+ ffi (~> 1.0.9)
+ json_pure
+ rubyzip
+ sprockets (2.0.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.4)
+ term-ansicolor (1.0.7)
+ therubyracer (0.9.9)
+ libv8 (~> 3.3.10)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ twitter-bootstrap-rails (1.4.1)
+ actionpack
+ jquery-rails (~> 1.0)
+ less
+ less-rails (~> 2.1.0)
+ railties
+ tzinfo (0.3.31)
+ uglifier (1.1.0)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+ warden (1.1.0)
+ rack (>= 1.0)
+ will_paginate (3.0.2)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ capybara (>= 1.1.1)
+ coffee-rails (~> 3.1.1)
+ cucumber-rails (>= 1.2.0)
+ database_cleaner (>= 0.6.7)
+ devise (>= 1.4.9)
+ factory_girl_rails (>= 1.3.0)
+ growl
+ guard (>= 0.6.2)
+ guard-bundler (>= 0.1.3)
+ guard-cucumber (>= 0.6.1)
+ guard-livereload (>= 0.3.0)
+ guard-rails (>= 0.0.3)
+ guard-rspec (>= 0.4.3)
+ jquery-rails
+ launchy (>= 2.0.5)
+ rails (= 3.1.1)
+ rails-footnotes (>= 3.7)
+ rb-fsevent
+ rspec-rails (>= 2.8.0.rc1)
+ sass-rails (~> 3.1.4)
+ sqlite3 (= 1.3.4)
+ twitter-bootstrap-rails
+ uglifier (>= 1.0.3)
+ will_paginate
View
3 app/controllers/posts_controller.rb
@@ -28,6 +28,9 @@ def create
end
def destroy
+ @post = Post.find(params[:id])
+ @post.destroy
+ redirect_to root_path
end
end
View
1 app/controllers/users_controller.rb
@@ -2,6 +2,7 @@ class UsersController < ApplicationController
before_filter :authenticate_user!
def show
+ @vote = Vote.new(params[:vote])
@user = User.find(params[:id])
@posts = @user.posts.paginate(:page => params[:page])
@post = current_user.posts.build(params[:post])
View
1 app/controllers/votes_controller.rb
@@ -20,6 +20,7 @@ def create
redirect_to root_path
else
flash[:failure] = "You did not vote"
+ @posts = Post.popular
render 'posts/index'
end
View
8 app/models/vote.rb
@@ -1,6 +1,14 @@
class Vote < ActiveRecord::Base
attr_accessible :user_id, :post_id
+ validate :only_one_user_per_post
belongs_to :user
belongs_to :post, :counter_cache => true
+
+private
+ def only_one_user_per_post
+ if Vote.where("user_id = ? AND post_id = ?", self.user_id, self.post_id).all.any?
+ errors.add(:user_id, "Can only post once per post!")
+ end
+ end
end
View
2 app/views/layouts/application.html.erb
@@ -20,7 +20,7 @@
<div class="topbar">
<div class="fill">
<div class="container">
- <h3><a href="#">Learning Quotient</a></h3>
+ <h3><%= link_to "Learning Quotient", posts_path %></h3>
<ul>
<%= render 'shared/navigation' %>
</ul>
View
9 app/views/posts/_post.html.erb
@@ -10,7 +10,14 @@
<h3><%= link_to post.title, post.link %></h3>
<% end %>
<p><%= post.content %></p>
- <small><%= post.user.name %></small>
+ <small><%= link_to post.user.name, post.user %></small>
+ <% if user_signed_in? %>
+ <% if current_user == @user %>
+ <%= link_to "delete", post, :method => :delete,
+ :confirm => "You sure?",
+ :class => "danger btn"%>
+ <% end %>
+ <% end %>
</div>
<%= f.hidden_field "post_id", :value => post.id %>
<%= f.hidden_field "user_id", :value => post.user.id %>
View
4 app/views/posts/index.html.erb
@@ -20,6 +20,10 @@
<li><%= link_to "New", :controller => "posts", :action => "new" %></li>
</ul>
+<% flash.each do |key, value| %>
+ <div class="flash <%= key %>"><%= value %></div>
+<% end %>
+
<table class="posts" summary="User posts">
<%= render @posts %>
</table>
View
4 app/views/users/show.html.erb
@@ -3,8 +3,6 @@
<table class="posts" summary="User posts">
<%= render @posts %>
</table>
- <%= will_paginate @posts %>
<% end %>
- Write a new post:
- <%= render 'shared/post_form' %>
+

0 comments on commit 4b8dbcc

Please sign in to comment.
Something went wrong with that request. Please try again.