Support for nested parameters in button_to params option

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

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’ } …

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.