Ruby - Rails 4 - Pundit - Policy and authorization error for a route #index_fr? -


sorry, didn't see place ask question pundit... thank help.

i working on ruby on rails api , create url (.../api/v1/attractions/fr) list information 1 of models. i've got error message pundit :

pundit::authorizationnotperformederror @ /api/v1/attractions/fr api::v1::attractionscontroller

and error verify_authorized in lib/pundit.rb file

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

this configuration :

# app/config/routes.rb  namespace :api, defaults: { format: :json }     namespace :v1       resources :lines, only: [ :index, :show ]         collection           '/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 

try adding before_filter :skip_authorization api controller.

however pundit verify_authorized method should called if you've added after_action.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -