我试图添加的按钮是一个按钮,当按下时,将“准确”值递增1.我查看了很多很多StackOverflow解决方案,但没有一个他们迄今为止为我工作。我正在和一位同事的代码一起工作,如果有帮助,大部分代码都是从Ruby on Rails教程中获取的(“通过示例学习Rails”),并且可能会被黑客入侵。Ruby on Rails 3投票系统上的路由错误
我的看法是这样的:
<%= link_to 'Accurate2', :action => :vote_up, :id => @post.id%>
我的代码如下所示:
def vote_up
#in posts_controller.rb
@post = Post.find(params[:id])
@post.rate_it(1, current_user.id) #with "acts_as_rateable" plugin
@post.save
我的路由是这样的:
resources :users do
resources :comments
resources :posts
end
resources :posts do
resources :comments
match "vote_up", :on => :collection
match "vote_down", :on => :collection
end
我收到的错误是:
http://localhost:3000/posts/vote_up?id=1
CanCan::AccessDenied in PostsController#vote_up
You are not authorized to access this page.
Parameters:
{"id"=>"1"}
似乎它与CanCan gem有关。将有助于知道你是如何使用它。 –