Topic: Clearing Form Field with link_to function

I have a link which shows a hidden div containing a simple form. For some reason, even though I am calling up the "new" method, the fields of my form are populated by the current content. I need to have these fields be cleared when I click on the link which shows them..

<%= link_to_function "New Project", "Element.show('my_form')" %>
<div id="my_form" style="display:none;">
<%= link_to_function "Close", "$('my_form').hide()", :class => 'close' %>
<% form_for(:project, :url => projects_path, :success => "$('my_form').hide()")  do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag "Create" %>   
<% end %>
</div>

Re: Clearing Form Field with link_to function

Is @project defined in your controller action? The form fields will default to this. Try passin a new project in the form_for call.

<% form_for(:project, Project.new, :url => projects_path, :success => "$('my_form').hide()")  do |f| %>

Railscasts - Free Ruby on Rails Screencasts

Re: Clearing Form Field with link_to function

I managed to fix the problem myself by specifying value => '' on the individual inputs. Your solution is much more elegant however and helped me understand forms better. Thanks!