re rendering into a form/table

10 views
Skip to first unread message

Jedrin

unread,
Oct 11, 2011, 3:38:38 PM10/11/11
to Ruby on Rails: Talk

I have this inside of a template where I have a remote form with the
form fields inside of a table:
<div id='ingredients_div'>
<%= render :partial => 'ingredients',
:locals => {:attr => attr} %>
</div>


my "_ingredients.html.erb" template is like so:

-----------------------------------------



<tr><td><%= link_to 'Add Ingredient', {:action =>
'add_ingredient', :id =>attr}, :remote => true %>
</td></tr>



<% attr.my_ingredients.each do |ingred| %>
<%= fields_for 'ingredient[]',ingred do |fm| %>

<tr><td>
<% fld = 'del-' + ingred.id.to_s %>
<%= check_box_tag fld %>
<%= observe_field fld, :frequency => 0.5,
:url => {:action => 'delete_ingredient', :id => ingred} %>
</td></tr>
<tr>
<td>Name</td><td><%= fm.text_field 'ingred_name', :value =>
ingred.name %> </td>
</tr>
<tr>
<td>Cas</td><td> <%= fm.text_field 'cas', :value => ingred.cas %> </
td>
</tr>
<tr><td>&nbsp</td></tr>
<% end %>
<% end %>


-----------------------------

my rjs actions try to delete/add an ingredient record or add one and
then re render
the partial like this:

page.replace_html 'ingredients_div', :partial =>
'ingredients', :locals => {:attr => attr}

I can't remember if there is some html rule with form fields or table
rules, but the html seems to get modified as the page kind of
twitches, but the fields don't redisplay as they should. The view
source confuses me as it appears the div moved someplace else and left
the old fields intact where they where.

Colin Law

unread,
Oct 11, 2011, 4:03:29 PM10/11/11
to rubyonra...@googlegroups.com

You have not shown us how the form itself is fitted into or around the
table. A form cannot lie inside a table unless it is entirely within
one cell. A table can lie entirely within a form.

If you are not sure whether you have valid html copy the entire page
source (View > Page Source or similar in your browser) and paste it
into the w3c html validator. Once you have valid html then try the
remote stuff again.

Colin

Reply all
Reply to author
Forward
0 new messages