使用 Ryan Bates 时出现 current_user 错误CanCan授权插件
适用的视图部分:
<% @projects.each do |project| %>
<tr>
<td><%= project.name %></td>
<td><%= project.description %></td>
<td><%= link_to 'Show', project %></td>
<% if can? :update, @project %>
<td><%= link_to 'Edit', edit_project_path(project) %></td>
<% end %>
<% if can? :destroy, @project %>
<td><%= link_to 'Destroy', project, :confirm => 'Are you sure?', :method => :delete %></td>
<% end %>
</tr>
<% end %>
models/ability.rb
class Ability
include CanCan::Ability
def initialize(designer)
can :read, :all
end
end
这是我得到的错误:
NameError in Projects#index
undefined local variable or method `current_user' for #<ProjectsController:0x000001016d62d8>
Extracted source (around line #18):
15: <td><%= project.description %></td>
16: <td><%= link_to 'Show', project %></td>
17:
18: <% if can? :update, @project %>
19: <td><%= link_to 'Edit', edit_project_path(project) %></td>
20: <% end %>
21:
想法?
The portion of the view that is applicable:
<% @projects.each do |project| %>
<tr>
<td><%= project.name %></td>
<td><%= project.description %></td>
<td><%= link_to 'Show', project %></td>
<% if can? :update, @project %>
<td><%= link_to 'Edit', edit_project_path(project) %></td>
<% end %>
<% if can? :destroy, @project %>
<td><%= link_to 'Destroy', project, :confirm => 'Are you sure?', :method => :delete %></td>
<% end %>
</tr>
<% end %>
models/ability.rb
class Ability
include CanCan::Ability
def initialize(designer)
can :read, :all
end
end
This is the error I get:
NameError in Projects#index
undefined local variable or method `current_user' for #<ProjectsController:0x000001016d62d8>
Extracted source (around line #18):
15: <td><%= project.description %></td>
16: <td><%= link_to 'Show', project %></td>
17:
18: <% if can? :update, @project %>
19: <td><%= link_to 'Edit', edit_project_path(project) %></td>
20: <% end %>
21:
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的 AuthLogic 安装出现错误。或者更确切地说,不是错误,而是当我安装它时,我使用了 current_designer (这是我关注的主要用户)而不是 current_user 。
CanCan 似乎不喜欢这样。
所以我现在正在重新做我所有的用户模型。但到目前为止,似乎已经解决了这个问题。
I had errors in my AuthLogic install. Or rather, not errors, but when I installed it I used current_designer (which was the main user I was concentrating on) rather than current_user.
It seems CanCan didn't like that.
So I am now in the process of re-doing all my user models. But so far, it seems to have fixed this issue.