我正在使用 thumbs_up gem,似乎我有一些工作要做,直到投票给一个帖子完全没有做任何事情。现在,单击此帖子链接的投票会导致一个空白页面,其 URL 为:localhost:3000/posts/1/vote_up
理想情况下,我会通过增加帖子的投票数来完成这项工作
我的路线文件
Projectmadrone::Application.routes.draw do
#devise_for :users
devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end
resources :posts do
member do
post :vote_up
end
end
root :to => 'posts#index'
end
我的控制器方法
def vote_up
begin
current_user.vote_for(@post = Post.find(params[:id]))
render :nothing => true, :status => 200
rescue ActiveRecord::RecordInvalid
render :nothing => true, :status => 404
end
end
app/views/post/index.html.erb
<% @posts.each do |post| %>
<li><%= post.content %></li>
<li><%= post.attribution %> in <%= post.neighborhood %>
<span class="post-date"><%=time_ago_in_words(post.created_at) %> ago</span></li>
<li> <%= bucket((post.neighborhood)) %> </li>
<li>Num votes: <%= post.votes_for %></li>
<li><%= link_to('vote this post!', vote_up_post_path(post), :method => :post) %></li>
<% end %>
</ul>