Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails cancan在视图中的错误是什么_Ruby On Rails_Ruby On Rails 4_Authorization_Cancan - Fatal编程技术网

Ruby on rails cancan在视图中的错误是什么

Ruby on rails cancan在视图中的错误是什么,ruby-on-rails,ruby-on-rails-4,authorization,cancan,Ruby On Rails,Ruby On Rails 4,Authorization,Cancan,我使用cancan在控制器中授权用户,在视图中我使用Can?检查用户是否有权查看该功能 index.html.erb <p id="notice"><%= notice %></p> <h1>Listing Noticeboards</h1> <table class="table table-bordered table-striped"> <thead> <tr> &l

我使用cancan在控制器中授权用户,在视图中我使用
Can?
检查用户是否有权查看该功能

index.html.erb

<p id="notice"><%= notice %></p>

<h1>Listing Noticeboards</h1>

<table class="table table-bordered table-striped">
  <thead>
    <tr>
      <th>society</th>
      <th>Notice heading</th>
      <th>Notice text</th>
      <th>Active</th>
      <th>Isdelete</th>
      <th>Expire</th>
      <th colspan="3"></th>
    </tr>
  </thead>

  <tbody>

    <% @noticeboards = @noticeboards.where(Isdelete: 0).find_each %>
      <% @noticeboards.each do |noticeboard| %>
        <tr>
          <td><%= Society.find_by(id: noticeboard.id_society, Isdelete: 0).name %></td>
          <td><%= noticeboard.notice_heading %></td>
          <td><%= noticeboard.notice_text %></td>
          <td><%= noticeboard.active %></td>
          <td><%= noticeboard.IsDelete %></td>
           <td><%= noticeboard.Expire %></td>
          <td><%= link_to 'Show', noticeboard %></td>
           <% if can? :update, noticeboard %>
          <td><%= link_to 'Edit', edit_noticeboard_path(noticeboard) %> <% end %></td>
          <% if can? :delete , noticeboard %>
          <td>
            <%= link_to 'Destroy', noticeboard, method: :delete, data: { confirm: 'Are you sure?' } %></td> <% end %>
        </tr>
      <% end %>

  </tbody>
</table>

<br>
 <% if can? :create, @noticeboard %>
<%= link_to 'New Noticeboard', new_noticeboard_path %>
<% end %>

上市公告栏 社会 通知标题 通知文本 活跃的 伊斯德莱特 到期

在这种情况下,如果我将:delete更改为其他任何内容,请说:您好,它仍在检查can,如果我没有使用任何内容,它会显示错误,并显示“错误的参数数”。错误是什么,为什么不使用:delete函数?

can?:更新使用了错误的noticeboard变量,它是@noticeboard,但应该是noticeboard。哦,是的,我更改了代码,它仍然没有显示任何错误,并且仍然遵循Can@jfornoffI不确定您的确切问题是什么,但也许这有助于您了解CanCan只是检查权限,而不限于Rails默认操作,因此您可以查询can:任何内容,通知栏,并获得正确/错误的响应(如果尚未定义,则默认为false)。所以它没有抛出任何错误是正确的。也许我无法解释我的问题,即使在更改方法名称时它也在进行身份验证,是的,如果没有定义方法,它将返回false,但其授权用户和管理员,管理员仍然可以看到destroy,用户仍然可以,如果cancan找不到该方法,它也应该向用户显示destroy,但它只向admin@jfornoff显示。也许您可以使用不同角色的授权设置更新您的帖子