chaps-io / access-granted

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

How to use with rails-api #13

Closed onordgren closed 9 years ago

onordgren commented 9 years ago

Hi,

What would be the correct approach to use access-granted with the rails-api gem? In rails-api the ActionController::Base is replaced with a scaled-down version so the controller methods won't be applied automatically by access-granted in https://github.com/chaps-io/access-granted/blob/master/lib/access-granted.rb.

Would a solution be to manually include the module like with cancan (https://github.com/ryanb/cancan/wiki/Rails-API-Gem) or is there any cleaner ways to solve this?

pokonski commented 9 years ago

I can add a detection for rails-api base controller (ActionController::API) easily :) For now you can create an initializer like in the CanCan wiki:

# config/initializers/access_granted.rb
ActionController::API.class_eval do
  include AccessGranted::Rails::ControllerMethods
end
onordgren commented 9 years ago

Great, thanks for the quick response :)

pokonski commented 9 years ago

I pushed a 0.2.1 version with that change :boom: