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 always uses outer :require #298

Closed
stephendolan opened this issue Jul 14, 2015 · 2 comments
Closed

permitted_attributes always uses outer :require #298

stephendolan opened this issue Jul 14, 2015 · 2 comments

Comments

@stephendolan
Copy link

I'm using Pundit in my API, and was going to try to filter parameters based on user role.

My issue is that instead of my requests being like the following for updating a user:

user: {
  first_name: "Test",
  last_name: "User"
}

They are formatted like this:

{
  first_name: "Test",
  last_name: "User"
}

The default method for permitted_attributes in Pundit source is here:

def permitted_attributes(record)
    name = record.class.to_s.demodulize.underscore
    params.require(name).permit(policy(record).permitted_attributes)
end

It would be great to have an options hash for this method that could specify something like not to use the .require(name) part.

@openface
Copy link

+1 agree.

Our API does not use root nodes either. We'll likely be hitting this same issue.

@jnicklas
Copy link
Collaborator

Pundit is all about conventions, and having params nested under a key is, like it or not, a very strong convention in the Rails world. It's really easy to override permitted_attributes to do whatever you want in your controller. If you're building an API which uses root level params, that's what you should do IMO. We can bend over backwards trying to accomodate all possible ways people might use Pundit, but I don't think that's a good idea.

Rather see Pundit as a set of ideas, and if they don't suit you somehow, it's easy to override them.

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

3 participants