Wednesday, 15 August 2012

erb - Rails form_tag in tag -



erb - Rails form_tag in <tr></tr> tag -

i have form_tag in lastly row of table

<tr> <%= form_tag(emails_path, method: :post) %> <td><%= text_field_tag 'email', nil, class: "form-control" %></td> <td><%= submit_tag "add", class: "btn btn-small btn-success" %></td> <% end %> </tr>

which render following

<tr> <form accept-charset="utf-8" action="/emails" method="post"></form> <!-- close here --> <td><input class="form-control" id="email" name="email" type="text"></td> <td><input class="btn btn-small btn-success" name="commit" type="submit" value="add"></td> </tr>

the "add" button not working because form tags not wrapping input controls in it.

but when seek take form out of table this

<%= form_tag(emails_path, method: :post) %> <p><%= text_field_tag 'email', nil, class: "form-control" %></p> <p><%= submit_tag "add", class: "btn btn-small btn-success" %></p> <% end %>

the form render correctly , "add" button works.

how can it? , remember used work....

you can't this.

your form tag cannot exist there, interspersed markup of table. has go within <td>. you're producing invalid markup, , browser interpreting best can.

you should utilize sec option, <p> tags, or rethink need have form span multiple table cells, or wrap entire table in single <form>.

ruby-on-rails erb

No comments:

Post a Comment