Hey Guys I am using Active Admin gem for admin panel and Pundit for authorization. Problem is I wanted new custom attribute in the policy scope so I modified it using pundit_user method in ApplicationController.rb Like this:
def pundit_user
UserContext.new(current_user, current_organization)
end
And My ApplicationPolicy.rb looks like this
attr_reader :user, :record, :organization
def initialize(user, record)
@user = user.user #Error Line
@organization = user.current_organization
@record = record
end
In Normal Rails Application this is working, but when I open active admin panel initialization is not being done.
Error Message
undefined method `user' for #<User id: 1, first_name: "Pavan", last_name: "Kumar", role: "vet", created_at: "2023-03-23 14:29:00.066387000 +0000", updated_at: "2023-03-24 06:39:27.092087000 +0000", email: "pavan.kumar@some.com", phone: "", dashboards: nil, profile_status: nil>
Relevant Code
UserContext
class UserContext
attr_reader :user, :current_organization
def initialize(user, current_organization)
@user = user
@current_organization = current_organization
end
end
Note: And I noticed whenever I go to admin routes it's not hitting the application controller.