I actually just copy the old question from railsforum when he asked it back in May 2009, and the only answer is authoring, which fixes an inelegant fix. I was wondering if anyone knows a better way? Otherwise, I'm going to end up using javascript to move a hidden field like it.
Here is the original question:
Hello! Thanks for any good advice on this topic:
Is it possible to override the automatic generation of hidden Rails identification fields in fields_for for the has_many association? I would like to create my own so that I can choose where it is.
That's why:
I am trying to place the jQuery-ui Accordion widget around a form that looks something like this:
<div id="diagram_elements_form">
<% diagram_form.fields_for :elements do |element_fields| %>
<% link_to "#" do %>
<%= element_fields.object.name %>
<% end %>
<%= render :partial => "edit_element_base", :locals => { :f => element_fields } %>
<% end %>
</div>
A simplified model is as follows:
class Diagram < ActiveRecord::Base
has_many :elements
accepts_nested_attributes_for :elements
end
, / , CRUD . .
jQuery UI/Accordion html :
<div id="accordion">
<a href="#">First header</a>
<div>First content</div>
<a href="#">Second header</a>
<div>Second content</div>
</div>
, . , , , , - _, __. , , :
<div id="accordion">
<input type="hidden" name="...id" value="2" />
<a href="#">First header</a>
<div>First content</div>
<input type="hidden" name="...id" value="3" />
<a href="#">Second header</a>
<div>Second content</div>
</div>
... . DIV. ?
,
, . , _for, , , javascript.
railsforum, , , .
,
.