chaps-io / access-granted

Multi-role and whitelist based authorization gem for Rails (and not only Rails!)
MIT License
775 stars 41 forks source link

Undefined method with ViewComponents #54

Closed choilive closed 2 years ago

choilive commented 2 years ago

I am getting an undefined method can? when attempting to use access-granted inside a view component.

https://github.com/github/view_component

Any ideas/suggestions in order to get this to work?

choilive commented 2 years ago

Figured it out.

Just needed to add include AccessGranted::Rails::ControllerMethods into my component class and delegate current_user through the view component helpers escape hatch.

jrochkind commented 2 years ago

I think maybe you could also have delegated the can? method to the helpers, without include AccessGranted::Rails::ControllerMethods?

pokonski commented 2 years ago

That's a good point and probably cleaner :)

choilive commented 2 years ago

I think maybe you could also have delegated the can? method to the helpers, without include AccessGranted::Rails::ControllerMethods?

Ah, that also works. Will try that for a future project :)