Note that there are some explanatory texts on larger screens.

plurals
  1. POuse cancan and devise in my application
    primarykey
    data
    text
    <p>I want to use <code>cancan</code> in order to limit the users that want to view some pages in my application.</p> <p>so I try to do it by this tutorial: <a href="http://www.roberthuberdeau.com/articles/9-Blog-tutorial-part-3" rel="nofollow">http://www.roberthuberdeau.com/articles/9-Blog-tutorial-part-3</a></p> <p>I have two roles: Admin and Worker, and I have two controllers: Tasksadmins and Workers.</p> <p>I want to define the next thing:</p> <p>1) Workers can manage and see all the things of the Workerscontroller.</p> <p>2) Admins can manage and see all the things of the Tasksadminscontroller.</p> <p>I'm not sure if I defined it correctly:</p> <pre><code>class Ability include CanCan::Ability def initialize(user) user ||= User.new # guest user if user.role? :Admin can :manage, :tasksadmins elsif user.role? :Worker can :manage, :workers end end end </code></pre> <p>the next thing that I think I don't need to implement is: "the def initialize user bit is for guest users." I force the users to sign_in with: <code>before_filter :authenticate_user</code></p> <p>the next thing is: start restricting access to the blog application based on user role:</p> <p>I don't know what and where I should write.</p> <p>in the example, he wrote:</p> <pre><code>authorize! :edit, @article </code></pre> <p>so I tried to write the next followings in the tasksadmins controller: </p> <pre><code>authorize! :edit, @tasksadmins authorize! :new, @tasksadmins authorize! :index, @tasksadmins authorize! :create, @tasksadmins authorize! :show, @tasksadmins authorize! :destroy, @tasksadmins </code></pre> <p>but I got an error: <code>undefined method 'authorize!' for TasksadminsController:Class</code></p> <p>please help me, I'm in the end of the definition of <code>cancan</code>.</p>
    singulars
    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.
 

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