CommonThread

end_form_tag Deprecated in Rails 1.2

Posted by ben, Tue Feb 27 00:55:00 UTC 2007

I you are used to doing forms in rails you probably used either start_form_tag or form_tag to open a form and end_form_tag to close it similar to this:

<%= form_tag :controller => 'users', :action => "search" %>
<%= text_field 'search', 'criteria' %>
<%= submit_tag 'Find a Friend' %>
<%= end_form_tag %>

This technique has been deprecated in Rails 1.2 and will be removed from the 2.0 release. Instead, you need to put the form inside of a block and pass it to the form_tag function like this:

<% form_tag(:controller => 'users', :action => "search") do %>
<%= text_field 'search', 'criteria' %>
<%= submit_tag 'Find a Friend' %>
<% end %>

Notice that we put the form inside of a block by adding do after the form_tag call and the end_form_tag was replaced by end and the <%= was changed to <% for the form_tag and end.

That should stop those annoying notices in your log and get you complient for the 2.0 release.

Filed Under: | Tags:

Comments

  1. matias quaglia 11.25.07 / 08AM
    Well, thank you very much for the enlightment. I'm learning rails following the book beginning rails e-commerce from apres, and when i runned the rake tests i saw the information about this outdated technique, so i was looking for the current way to do it, thank you very much, ben!
  2. a 06.19.08 / 03AM
    thanks!
  3. Ryuk 08.13.08 / 12PM
    Thanks for your help. Needed for paypal library, lol. Evil form tags.

Have your say

A name is required. You may use HTML in your comments.




Categories