Skip to content
This repository has been archived by the owner on Aug 17, 2017. It is now read-only.

Confusing permits for requirement. #176

Open
seivan opened this issue Oct 29, 2013 · 2 comments
Open

Confusing permits for requirement. #176

seivan opened this issue Oct 29, 2013 · 2 comments

Comments

@seivan
Copy link

seivan commented Oct 29, 2013

params.require(:user).permit(:name, :weight, :avatar)

I read that, as it requires :name inside :user

But from the looks of it, it just requires that :name exists somewhere in params, even outside of :user

Doing a request with nothing but @{@"name" : @"TheNameWrittenHere"};

That sorta (by checking the rails logs) put the :name with its value inside :user

Could someone please clarify this?

Parameters: {"name"=>"TheNameWrittenHere", "user"=>{"name"=>"TheNameWrittenHere"}}
@coreyward
Copy link

require requires the argument you pass, so to speak, so in this example the only thing you're requiring is :user.

You are also permiting the use of three additional keys: :name, :weight, :avatar under :user, thus:

{ user: { name: 'selvan', weight: 100, avatar: 'pink_dude.png' } }

@seivan
Copy link
Author

seivan commented Apr 25, 2014

@coreyward Thanks for responding.

But this doesn't make things any clearer.
I just did a request with name "name" : "TheNameWrittenHere" without any user at all, and it still worked. As in it permitted "name" outside "user" - in fact, there wasn't even a "user" there in the request.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants