thumbs_up中的vote_up转到空白页面

时间:2012-09-03 21:01:37

标签: ruby-on-rails

我正在使用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

应用/视图/后/ 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>

1 个答案:

答案 0 :(得分:0)

这一行看起来很可疑:

render :nothing => true, :status => 200

似乎会告诉控制器呈现您正在看到的空白页面。尝试将其评论出来,看看是否能解决问题。希望有所帮助!