2012-09-03 23 views
0

我正在使用thumbs_up宝石,似乎我得到的东西工作,直到一个职位的投票绝对没有。现在,点击投票此帖链接指向的URL一个空白页:本地主机:3000 /职位/ 1/vote_upthumbs_up 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> 

回答

0

这行看起来可疑:

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

好像会告诉控制器来呈现你所看到的空白页。尝试评论一下,看看是否修复它。希望有所帮助!

+0

不幸的是,这给了我一个没有方法的错误:未定义的方法'vote_for'为零:NilClass – amritha

+0

@amritha - 这个错误听起来像'current_user'没有定义。你确定它已被加载,而不是'无'? –

+0

我该如何检查? – amritha