Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'permitted_attributes' method collides with pundit #417

Closed
kuboon opened this issue Jan 18, 2016 · 5 comments
Closed

'permitted_attributes' method collides with pundit #417

kuboon opened this issue Jan 18, 2016 · 5 comments

Comments

@kuboon
Copy link

kuboon commented Jan 18, 2016

if I include Pundit on my Administrate controller, it raises ArgumentError on create / update.

class ApplicationController < Administrate::ApplicationController
  include Pundit
  # ...
end

The problem is calling permitted_attributes actually calls the method in Pundit.
https://github.com/elabs/pundit/blob/master/lib/pundit.rb#L248
What is a better way to avoid this collision rather than monkey-patching on either of gems?

@lserman
Copy link

lserman commented Jan 23, 2016

I ran into this as well, I ended up just overriding resource_params to call dashboard.permitted_attributes directly:

def resource_params
  params.require(:user).permit(dashboard.permitted_attributes)
end

Definitely not ideal. Luckily I only need Pundit on one of my Administrate controllers for now.

c-lliope added a commit that referenced this issue Feb 14, 2016
Fixes #417

Problem:

If users include the Pundit gem on an Administrate controller,
the controller attempts to call the `permitted_attributes` method
defined by pundit instedad of the one defined by Administrate.

Because these methods take different arguments,
this results in an `ArgumentError` for the user.

Solution:

Inline the `permitted_attributes` method
to avoid the method name collision.
c-lliope added a commit that referenced this issue Feb 14, 2016
Fixes #417

Problem:

If users include the Pundit gem on an Administrate controller,
the controller attempts to call the `permitted_attributes` method
defined by pundit instedad of the one defined by Administrate.

Because these methods take different arguments,
this results in an `ArgumentError` for the user.

Solution:

Inline the `permitted_attributes` method
to avoid the method name collision.

This narrows the public API a bit, but that's alright.
The user can accomplish all of the removed functionality by overriding
the parent `resource_params` method.
@c-lliope c-lliope self-assigned this Feb 14, 2016
@wenweih
Copy link

wenweih commented Mar 29, 2016

👍

yknx4 pushed a commit to yknx4/administrate that referenced this issue Oct 17, 2016
Fixes thoughtbot#417

Problem:

If users include the Pundit gem on an Administrate controller,
the controller attempts to call the `permitted_attributes` method
defined by pundit instedad of the one defined by Administrate.

Because these methods take different arguments,
this results in an `ArgumentError` for the user.

Solution:

Inline the `permitted_attributes` method
to avoid the method name collision.

This narrows the public API a bit, but that's alright.
The user can accomplish all of the removed functionality by overriding
the parent `resource_params` method.
Envek pushed a commit to Envek/administrate that referenced this issue Oct 21, 2016
Fixes thoughtbot#417

Problem:

If users include the Pundit gem on an Administrate controller,
the controller attempts to call the `permitted_attributes` method
defined by pundit instedad of the one defined by Administrate.

Because these methods take different arguments,
this results in an `ArgumentError` for the user.

Solution:

Inline the `permitted_attributes` method
to avoid the method name collision.

This narrows the public API a bit, but that's alright.
The user can accomplish all of the removed functionality by overriding
the parent `resource_params` method.
@jasonswett
Copy link

@lserman's solution worked for me.

In case anyone, like me, has trouble connecting the dots, what you need to do is add @lserman's code to app/controllers/admin/application_controller.rb.

@carlosramireziii
Copy link
Collaborator

There's a PR for this #465 that will be in review shortly.

nickcharlton pushed a commit that referenced this issue Mar 7, 2017
Fixes #417

Problem:

If users include the Pundit gem on an Administrate controller,
the controller attempts to call the `permitted_attributes` method
defined by pundit instedad of the one defined by Administrate.

Because these methods take different arguments,
this results in an `ArgumentError` for the user.

Solution:

Inline the `permitted_attributes` method
to avoid the method name collision.

This narrows the public API a bit, but that's alright.
The user can accomplish all of the removed functionality by overriding
the parent `resource_params` method.
fwolfst pushed a commit to fwolfst/administrate that referenced this issue Mar 8, 2017
Fixes thoughtbot#417

Problem:

If users include the Pundit gem on an Administrate controller,
the controller attempts to call the `permitted_attributes` method
defined by pundit instedad of the one defined by Administrate.

Because these methods take different arguments,
this results in an `ArgumentError` for the user.

Solution:

Inline the `permitted_attributes` method
to avoid the method name collision.

This narrows the public API a bit, but that's alright.
The user can accomplish all of the removed functionality by overriding
the parent `resource_params` method.
@jaykilleen
Copy link

jaykilleen commented Jun 14, 2017

Thanks @lserman and @jasonswett I have followed your instructions and now have fixed the Administrate Pundit wrong number of arguments (given 0, expected 1..2) error. I have to slightly tweak the code so it referenced resource instead of user so that it worked across all the objects.

    def resource_params
      params.require(resource_name).permit(dashboard.permitted_attributes)
    end

@c-lliope c-lliope removed their assignment Nov 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants