I'm getting undefined method 'authorize_actions_for'
in the controller when using rails-api with the Authority gem . Any ideas what I need to include? Here's my code:
Gemfile:
...
gem 'authority', '~> 2.9.0'
gem 'rails-api', '~> 0.1.0'
...
app/authorizers/session_authorizer.rb:
class SessionAuthorizer < ApplicationAuthorizer
def deletable_by?(user)
user.sessions.include?(resource)
end
end
app/controllers/v1/sessions_controller.rb:
class V1::SessionsController < ApplicationController
authorize_actions_for Session
...
end
Authority::Controller
As we discussed on Github , authorize_actions_for
is defined in Authority::Controller
.
In a normal Rails app, that module gets included into ActionController::Base
by Authority's railtie.rb
. Apparently the railtie isn't being required when using rails-api (maybe the Rails
constant isn't defined?).
You can include the appropriate module yourself, though:
class ApplicationController < ActionController::Base
include Authority::Controller
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.