cancan

uninitialized constant Ability Rails

孤街浪徒 提交于 2021-02-10 16:25:19
问题 I have gone through different solutions given to this problem but none of them is working so please don't try to close the question as duplicate. I have role column in my users table. So user can by admin or user and I need to put permissions on the base of user Role using CanCan . I want to give all permissions to admin. I am logged in as admin but when I access /users I get the error uninitialized constant Ability and when I remove load_and_authorize_resource my cancan permission doesn't

Rails - defining cancan ability using associations

杀马特。学长 韩版系。学妹 提交于 2021-02-08 07:05:23
问题 When defining abilities in the cancan Ability class... Is this: can :manage, Area, :location => { :company => { :manager => { :user_id => user.id } } } The same as this: can :manage, Area do |area| area.location.company.manager.user_id == user.id end I'm just trying to better understand defining an ability without using a block. Is one way better (maybe faster) than the other? 回答1: The two should be the same, however the second way is much clearer if anyone else is reading your code. I would

Rails - defining cancan ability using associations

时光总嘲笑我的痴心妄想 提交于 2021-02-08 07:02:49
问题 When defining abilities in the cancan Ability class... Is this: can :manage, Area, :location => { :company => { :manager => { :user_id => user.id } } } The same as this: can :manage, Area do |area| area.location.company.manager.user_id == user.id end I'm just trying to better understand defining an ability without using a block. Is one way better (maybe faster) than the other? 回答1: The two should be the same, however the second way is much clearer if anyone else is reading your code. I would

How to authorize namespace, model-less controllers using CanCanCan?

£可爱£侵袭症+ 提交于 2021-01-29 04:34:15
问题 What is the correct way to authorize and check abilities for a namespaced, model-less controller using CanCanCan? After much googling and reading the wiki, I currently have #controllers/namespaces/unattacheds_controller.rb def Namespaces::UnattachedsController authorize_resource class: false def create # does some stuff end end #models/ability.rb def admin can [:create], :namespaces_unattacheds end #view/ <%= if can? :create, :namespaces_unattacheds %> # show a create form to authorized users

check_authorization causes custom devise controller to fail?

て烟熏妆下的殇ゞ 提交于 2021-01-07 02:52:34
问题 Background I have a simple app with devise and cancancan. Because I wanted to add a little bit of custom logic to the signup process, I used devise with customised controllers, which simply means devise uses the users controller (rather than devise controllers) for all of the things devise does. Problem When I add check_authorization to the application controller, and skip_authorization_check to all of the user (devise) controllers, I still get the following error raised when the user tries

check_authorization causes custom devise controller to fail?

冷暖自知 提交于 2021-01-07 02:51:41
问题 Background I have a simple app with devise and cancancan. Because I wanted to add a little bit of custom logic to the signup process, I used devise with customised controllers, which simply means devise uses the users controller (rather than devise controllers) for all of the things devise does. Problem When I add check_authorization to the application controller, and skip_authorization_check to all of the user (devise) controllers, I still get the following error raised when the user tries

Why does current_user session become nil when updating a user?

瘦欲@ 提交于 2020-06-25 04:00:10
问题 I'm using Devise and CanCan for user authentication and administrating roles restricting access to parts of my Rails 4 app for certain users. I've run into some problems with updating a user. The update works fine and the user object in the db get updated as it should, but my user session is lost on the following redirect_to my user show action. current_user becomes nil which means that CanCan restricts the access to the user show action. Why does current_user become nil after update, when

CANCAN => Admin + Agent + User

夙愿已清 提交于 2020-03-06 09:55:15
问题 Need Help! :) Use Case: Admin can create another admin when he have role of "SuperAdmin", Admin Can also Create "Agents" Roles for Admin Model: SuperAdmin Admin Admin can create both the roles can create "Agents" Agent can create "User" but he will not be able to create "Agents" and he should not see users created by other Agents. He has only one Role - "Agent" Now the problem is : how to initialize "admin", "agent" & "user" in Ability as they are are 3 different models ? class Ability def