Support for nested parameters in button_to params option

291 views
Skip to first unread message

James Coleman

unread,
Sep 11, 2014, 6:01:05 PM9/11/14
to rubyonra...@googlegroups.com
In this commit the `params` option was added to the `button_to` helper. However, the patch doesn't support nested hashes so `{a: {b: 'c'}}` for example gets turned into a hidden form input with the name 'a' and the value being the string representation of the `{b: 'c'}` nested hash.

Since Rails supports nested hashes everywhere else (and even in the URL params of link_to and button_to), I believe this to be a bug/unfinished feature. Unless the other disagree with that assessment, I'm planning to submit a patch to add the missing functionality.

I had question though on implementation: I can't find any support in Rails for turning a nested hash into a list of name/value pairs for form inputs. `to_query` exists on Hash, of course, but it specifically escapes the keys and joins the keys and values as fits a URI. In my patch I can either write one-off code within the button_to helper to accomplish what I need, or I can add a new Hash extension to ActiveSupport. What's the best/expected way to go about tackling this issue?

Thanks,
James

Günter Glück

unread,
Apr 15, 2015, 11:07:32 AM4/15/15
to rubyonra...@googlegroups.com
Hi James,

you can use something like this to get nested params. But I guess you're right, it would be nice to have the nested hashes syntax working as expected.

... params: { 'some_model[attribute_name]' => 'the value' } ....

James Coleman

unread,
Apr 15, 2015, 4:27:18 PM4/15/15
to rubyonra...@googlegroups.com
Günter,

I actually implemented the functionality in this pull request: https://github.com/rails/rails/pull/17043 -- but have gotten no feedback at all from the core team. If you'd check out the PR, run the tests, and confirm the code looks good, it'd be helpful to comment that on the PR.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages