2016-10-26 15 views
0

申し訳ありませんが、私はPunditについて質問する別の場所を見ませんでした...あなたの助けをありがとう。Ruby - Rails 4 - Pundit - ルート#index_frのポリシーと承認エラー?

私はRuby on rails APIを開発中で、私のモデルのいくつかの情報をurl(.../api/v1/attractions/fr)リストに作成したいと思います。でverify_authorized用/ API/V1 /アトラクション/ FR アピ:: V1 :: AttractionsController

評論家:: AuthorizationNotPerformedErrorと、このエラー:しかし、私は評論家から、このエラーメッセージを持っていますLIB/pundit.rbファイル

def verify_authorized 
    raise AuthorizationNotPerformedError, self.class unless pundit_policy_authorized? 
end 

は、これは私の設定です:

# app/config/routes.rb 

namespace :api, defaults: { format: :json } do 
    namespace :v1 do 
     resources :lines, only: [ :index, :show ] do 
     collection do 
      get '/fr', to: 'attractions#index_fr' 
     end 
     end 
    end 
end 

# app/controllers/api/v1/attractions_controller.rb 

class Api::V1::AttractionsController < Api::V1::BaseController 
skip_before_action :authenticate_user! 

    def index 
    @attractions = policy_scope(Attraction) 
    @attractions = Attraction.all 
    end 

    def index_fr 
    @attractions = policy_scope(Attraction) 
    @attractions = Attraction.all 
    end 
end 

# app/policies/application_policy.rb 

class ApplicationPolicy 
    attr_reader :user, :record 

    def initialize(user, record) 
    @user = user 
    @record = record 
    end 

    def index? 
    false 
    end 

    def index_fr? 
    false 
    end 

    def create? 
    false 
    end 

    def new? 
    create? 
    end 

    def update? 
    false 
    end 

    def edit? 
    update? 
    end 

    def destroy? 
    false 
    end 

    def scope 
    Pundit.policy_scope!(user, record.class) 
    end 

    class Scope 
    attr_reader :user, :scope 

    def initialize(user, scope) 
     @user = user 
     @scope = scope 
    end 

    def resolve 
     scope 
    end 
    end 
end 
end 

答えて

0

あなたのAPIコントローラにbefore_filter :skip_authorizationを追加してみてください。

しかし、専門家verify_authorizedメソッドは、after_actionとして追加した場合にのみ呼び出すようにしてください。

関連する問題