Code Monkey home page Code Monkey logo

Comments (8)

jekuno avatar jekuno commented on May 14, 2024 4

I had a similar issue. If you have a Admin::User model you may not use a simple symbol such as authorize :user because pundits policy finder will turn this into User (namespace missing) using object.to_s.camelize.

Check your parameter of the authorize call. You either have to provide your class (or an instance of it) such as authorize Admin::User or you need to provide a prefixed symbol such as authorize :"admin/user".

from pundit.

jnicklas avatar jnicklas commented on May 14, 2024 2

Policies follow the namespacing of models, not of controllers, so if you had an Admin::User model, you could use a Admin::UserPolicy policy.

from pundit.

Sphaerus avatar Sphaerus commented on May 14, 2024 1

this is exactly the point, when i have it in folder you mentioned, pundit cant find it. when i just throw it into "policies" it works. i tried to solve it with "require_dependencies" in admin::users_controller pointing onto policies/admin, and it kinda works. kinda, because anytime i make a change in the policy, i get "superclass mismatch for class UserPolicy" and have to restart server.

from pundit.

delphaber avatar delphaber commented on May 14, 2024

And your user_policy.rb file must be saved in app/policies/admin folder

from pundit.

delphaber avatar delphaber commented on May 14, 2024

Actually it worked for me. My previous solution was manually defining policy class in namespaced class

module DepattoModels

  class Activity
    def self.policy_class
      ActivityPolicy
    end
  end
end

Is your policy class definition like this?

class Admin::UserPolicy [....]

from pundit.

Sphaerus avatar Sphaerus commented on May 14, 2024

Yes

from pundit.

delphaber avatar delphaber commented on May 14, 2024

Then... sorry I do not know why it doesn't work :(
I'm currently using pundit 0.2.1

from pundit.

rolandoalvarado avatar rolandoalvarado commented on May 14, 2024

This solves my issue. Thanks @jnicklas

from pundit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.