Partial being rendered outside of table format

I’m following this nested forms railscast
http://railscasts.com/episodes/197-nested-model-form-part-2

but each time that new fields are added to my form the fields are
added above my table. Therefore, when the remove links are clicked,
it can’t find the section to delete. What am I doing wrong?

in the view:

    <% echantillon_form.fields_for :treatments do |builder| %>
       <%=  render  "treatment_fields", :f => builder %>
    <% end %>

  <%= link_to_add_fields "Add treatment",

echantillon_form, :treatments %>

<%= echantillon_form.submit “Submit” %>
<% end %>

in the partial:

<%= f.label(:treatmenttype, “type de traitement”, :class => “name”) %>
<%= f.text_field :treatmenttype %>

<%= f.label(:treatmenttype, “commentaires sur la preparation”, :class
=> “name”) %>
<%= f.text_field :preparation %>

<%= f.hidden_field :_destroy %>

<%= link_to_remove_fields “remove”, f %>

You need to nest the table content inside


tags. It’s not valid HTML otherwise.

Regards,

Ryan

On 12 April 2010 16:59, ES [email protected] wrote:

name=“echantillon[treatments_attributes][1][treatmenttype]” size=“30”

<input id="echantillon_treatments_attributes_1__destroy"

while firebug says that the fields are actually outside of the


tags. Why would that be?

I think you have invalid html. I highly recommend installing the html
validator add-in for firefox as it checks my html as I develop the
app, making sure I do not make such errors. Also you can paste your
html into the w3c htlm validator (find with google if necessary) to
check it.

Colin

I just realized that Firebug doesn’t correctly display what content is
in what tags. The source file says this:

type de traitement commentaires sur la preparation

remove

while firebug says that the fields are actually outside of the


tags. Why would that be?

Also, why is it putting two hidden fields (shown above in the source
code) in the form while my view file says only this:

<%= f.label(:treatmenttype, "type de traitement", :class => "name") %> <%= f.text_field :treatmenttype %> <%= f.label(:treatmenttype, "commentaires sur la preparation", :class => "name") %> <%= f.text_field :preparation %> <%= f.hidden_field :_destroy %> <%= link_to_remove_fields "remove", f %>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs