Using a partial form with form_for
Posted on January 20, 2009, under Rails.
I just wanted to use partial form for CRUD using Rails 2.2.2 and when i had created a form i got the following error:
undefined local variable or method `f’ for #
Old Code
<% form_for(@project) do |f| %> <%= f.error_messages %> <%= render :partial => 'form' %> <% end %>
New Code
<% form_for(@project) do |f| %>
<%= f.error_messages %>
<%= render :partial => 'form', :locals => { :f => f } %>
<% end %>
Validating the Remote Form in Rails
I was trying to validate a form which has a Ajax Request i.e. the form has form_remote_tag
<%= form_remote_tag(:html =>{:autocomplete => "off"}, :loading => "Element.show('search_spinner')",:complete => "Element.hide('search_spinner')", :url =>{ :controller => "/order_domain", :action => "lookup" }) -%>
After googling I found the :before filter can be used with Form Remote Tag
<%= form_remote_tag(:html =>{:autocomplete => "off"}, :loading => "Element.show('search_spinner')",:complete => "Element.hide('search_spinner')", :before=> "if (!check_domain_name()) {return false;}", :url =>{ :controller => "/order_domain", :action => "lookup" }) -%>
and now the validation is true then the Ajax request would be placed otherwise it return false.
Also you may be interested to read more here