Search code examples
ruby-on-railsrubypundit

How Pundit passes current_user to authorize method?


Pundit's authorize takes 3 arguments, but in the controller you just need to pass 2, current_user is passed automatically. How is current_user passed? I looked at Pundit's code, but couldn't figure it out.


Solution

  • From pundit readme:

    The first argument is a user. In your controller, Pundit will call the current_user method to retrieve what to send into this argument

    From pundit.rb file:

    def pundit_user
      current_user
    end