Note that there are some explanatory texts on larger screens.

plurals
  1. PORails : Issue with cancan
    primarykey
    data
    text
    <p>I have created an app which uses devise and cancan for authentication and authorization . Using cancan I have defined two roles admin and operator. The admin can manage all and the operator can edit all but not destroy and the third is a normal user who can create and manage. But the code goes only to the default else block. This is my ability class and index.html </p> <pre><code>class Ability include CanCan::Ability def initialize(user) user ||= User.new # guest user if user.role? :admin can :manage, :all elsif user.role? :operator can :read, :all else can :read, :all end end end </code></pre> <p>index.html</p> <pre><code> &lt;h1&gt;Listing todos&lt;/h1&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Description&lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;/tr&gt; &lt;% @todos.each do |todo| %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= todo.name %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= todo.description %&gt;&lt;/td&gt; &lt;% if can? :show, @todo %&gt; &lt;td&gt;&lt;%= link_to 'Show', todo %&gt;&lt;/td&gt; &lt;% end %&gt; &lt;% if can? :update, @todo %&gt; &lt;td&gt;&lt;%= link_to 'Edit', edit_todo_path(todo) %&gt;&lt;/td&gt; &lt;% end %&gt; &lt;% if can? :destroy, @todo %&gt; &lt;td&gt;&lt;%= link_to 'Destroy', todo, :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt;&lt;/td&gt; &lt;% end %&gt; &lt;/tr&gt; &lt;% end %&gt; &lt;/table&gt; &lt;br /&gt; &lt;% if can? :destroy, @todo %&gt; &lt;%= link_to 'New Todo', new_todo_path %&gt; &lt;% end %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload