0

I have user_role table like this:

user_role_id (pk)
name (e.g admin)
access_one
access_two
acccess_three

and user_table with columns like:

user_id (pk)
user_role_id (fk)
username
password

I have view to create above users_roles through admin panel. Then how can I use the named roles ? so that I can get benefit of Role Inheritance in cancan & also I wish that list of rolenames should remain sync with database.
Further,
I wish to set access in ability.rb based on the access_one,access_two,etc. defined in user_role table.so,how can I accomplish this?

Chirag Rupani
  • 1,675
  • 1
  • 17
  • 37

1 Answers1

0

The best place to look is

Cancan-ability

Cancan has a very nice documentation. Just going through it would be quite helpful.

EDIT:

      user ||= User.new # guest user (not logged in)
        if user.admin?
          can :manage, :all
        elsif user.student?
          can :manage, [Book, Copies]
          can :manage, Theme
        else  
          can :read, :all
        end

      end

you can use can and cannot to take care of permissions. Like

can :manage, Model_name, Action_name 

This will make sure that a specific model is taken into consideration with privileges to speified view.

Bijendra
  • 9,467
  • 8
  • 39
  • 66