Git Product home page Git Product logo

Comments (4)

kouroubel avatar kouroubel commented on June 11, 2024 1

Thank you for taking the time. authorize Expense has solved the issue.

from pundit.

Burgestrand avatar Burgestrand commented on June 11, 2024

I'd guess that you have namespacing overrides somewhere in your code, probably something like this in your controller:

def authorize(record, query = nil)
  super([:expense, record], query)
end

If so then that's probably the reason for your issue.

If that's not the case, then a reproduce example would help a lot! A github repo or gist that we can run that exhibits the problem ☺️

from pundit.

kouroubel avatar kouroubel commented on June 11, 2024

I managed to strip down my application to the basic form that will reproduce this issue. Github repo available here. Heroku app that will fire the exception when you press the export button is here.

image

from pundit.

Burgestrand avatar Burgestrand commented on June 11, 2024

Hi!

I believe I found your issue. I missed it in your first example code.

  @expenses = Expense.find( params[:expense_ids] )
  
  authorize @expenses

@expenses here is an array of multiple records. When Pundit is passed an array like this the front items are assumed to be a namespace. This is the reason the lookup fails.

You either need to authorize Expense, which will use export? to authorize. If you need more context (e.g. which records are included?), perhaps modelling your export as an object on its own (ExportService) and authorizing that might be an idea worth exploring.

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.