This project is archived and is in readonly mode.
FormHelper#fields_for has illogical (and unused) option
-
RSL
I think you need this in fields_for because form_for actually uses fields_for internally.
-
Clemens Kofler
RSL: Good catch but that's not exactly true.
As I said, all tests pass which means it doesn't break any existing functionality. Moreover, form_for only uses fields_for internally to create the scope so you can say f.text_field :name and get product[name] instead of just name.
If you look at the exact call in form_for, it looks like this:
fields_for(object_name, *(args << options), &proc)So form_for passes in the object name (e.g. product), followed by the args (and it pushes the options hash it extracted before back in the array) and the given block. The options that apply_form_for_options! uses are tag-related and fields_for does never produce an actual tag - so the call is, as far as I see it, redundant.
Thanks for the comment, though! :)
-
RSL
Yeah. I read this in passing and just opened Rails source to verify and saw the same thing. I knew I remembered it using fields_for internally, just not the extent. :)
-
Ryan Bates
+1, I have some ideas on how passing an array to form_for can work (which probably deserves its own ticket) and getting this existing, odd behavior removed is a good first step.
-
josh
- Assigned user set to josh
-
Repository
- State changed from new to resolved
(from [938caf4e6b2448b45939d36824794ea0aa5e1804]) Removed unused option from FormHelper#fields_for [#641 state:resolved]
Signed-off-by: Joshua Peek
-
Yong Bakos
I'd like to chime in on this, with a recommendation on future behavior.
It sho would be nice if fields_for, when fed an array, would build field names with numbers.
For example, imagine an Order that has_many LineItems, and each LineItem belongs_to a Product.
fields_for @order.line_items do |lif| # field rendering <input name="line_items[1][quantity] /> endMaybe the bottom of this thread can help illustrate.