使用 Ryan Bates 时出现 current_user 错误CanCan授权插件

发布于 2024-10-02 07:17:45 字数 1369 浏览 2 评论 0原文

适用的视图部分:

<% @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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自我难过 2024-10-09 07:17:45

我的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文