【发布时间】:2013-02-01 12:47:03
【问题描述】:
两天后,我无法自己解决这个问题。看起来它应该很简单,但我错过了一些东西。我正在使用帖子和作者创建一个简单的博客。作者有一个布尔管理列。
现在给我一个错误的行是我检查权限以在帖子中显示编辑按钮。当前错误是:
帖子中的NoMethodError#show
显示 .../posts/show.html.erb 第 18 行出现的位置:
用于#的未定义方法`stringify_keys'
posts/show.html.rb
<% if @author.can? :update, @post %>
<p><%= link_to 'Edit', edit_post_path(@post), :class => 'btn' %> <%= link_to 'Destroy', @post, confirm: 'Are you sure?', method: :delete %></p>
<% end %>
application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_url, :alert => exception.message
end
helper_method :current_author
def current_user
@current_ability ||= Author.new(current_author)
end
end
ability.rb
class Ability
include CanCan::Ability
def initialize(author)
author ||= Author.new # guest user (not logged in)
if author.admin?
can :manage, :all
else
can :read, :all
end
end
end
此外,据我所知,CanCan 正确包含在 gem 文件中。
【问题讨论】:
标签: ruby-on-rails devise cancan