【发布时间】:2011-07-31 16:19:10
【问题描述】:
我要添加的只是一个按钮,当按下该按钮时,“准确度”值会增加 1。我已经查看了很多很多 StackOverflow 解决方案,但到目前为止,它们都没有为我工作。我正在使用一位同事的代码,如果有帮助,其中大部分来自 Ruby on Rails 教科书(“通过示例学习 Rails”),可能会被一起破解。
我的看法是这样的:
<%= 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 宝石有关。了解您的具体使用情况会很有帮助。
标签: ruby-on-rails ruby ruby-on-rails-3 routing