Моя первоначальная задача была решена, но это произошло снова, и не был установлен, используя тот же методПандит политика не нашла
Я пишу простой API в Rails, используя AuthLogic и Pundit для авторизации, и эта ошибка:
unable to find policy `SkryptPolicy` for `#<Skrypt id: 1, title: "Maths", route: "/maths/:action", script: "def main params[:one] * params[:two] if params[:ac...", user_id: nil, created_at: "2015-12-27 02:12:36", updated_at: "2015-12-27 02:12:36">`
Я не разрешающее nil
, как и большинство других проблем, с этим я нашел, и есть все соответствующие файлы, так что я не могу понять, что происходит.
Я также работаю над другим приложением, используя ту же комбинацию Pundit и AuthLogic, и работает отлично, даже используя те же имена файлов и классов.
Вот мой app/controllers/application_controller.rb
:
class ApplicationController < ActionController::Base
include Pundit
protect_from_forgery with: :null_session
before_filter { response.header['Access-Control-Allow-Origin'] = '*' if request.format.json? }
protected
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = (current_user_session && current_user_session.user) || User.find_by(api_key: params[:api_key])
end
end
app/policies/skrypt_policy.rb
:
class SkryptPolicy < Struct.new(:user, :skrypt)
class Scope < Scope
def resolve
user.skrypts
end
end
def index?
not user.nil?
end
alias_method :create?, :index?
def show?
user && (skrypt.user == user)
end
alias_method :update?, :show?
alias_method :destroy?, :show?
end