sinatra-strong-params icon indicating copy to clipboard operation
sinatra-strong-params copied to clipboard

Nested parameters?

Open Joshfindit opened this issue 8 years ago • 3 comments

One thing that Rails trips up on quite frequently is nested parameters. Does this gem handle them?

Example 1

works in Rails, but accepts everything in the array

get '/', allows: [:id, :action, :relationships[ ] ] do
  erb :index
end

Example 2

does not work in rails, but is the ideal

get '/', allows: [:id, :action, :relationships[ allows: [:id, name]] ] do
  erb :index
end

Joshfindit avatar Jan 24 '17 14:01 Joshfindit

Not currently, no. Though I don't know why we couldn't implement something like that.

Are you looking to nest :allows and :needs within each other? That might get complicated... but being able to just allow certain parts of nested parameters should be doable. I'm thinking something like this:

get '/', allows: [:id, :action, :relationships[:id, name]] do
  erb :index
end

Which would allow only the :id and :name params inside of the :relationships param.

evanleck avatar Jan 30 '17 18:01 evanleck

Not looking to nest :allows and :needs within each other, no; it feels like madness lies that way at anything past 2 levels.

That syntax makes sense. How do you feel about people abusing the system with the following or worse?

get '/', allows: [:id, :action, :relationships[:id, :name, :parents[:id, :name, :grandparents[:id, :name, :sisters[:id, :name]]]]] do
  erb :index
end

Joshfindit avatar Jan 30 '17 21:01 Joshfindit

I agree, that seems like chaos.

Seems pretty wild, but there's no reason it shouldn't work. We'd just have to implement it so we can recurse through nested arrays.

evanleck avatar Jan 30 '17 21:01 evanleck