RailsCasts Pro episodes are now free!
Learn more or hide this
Note: This solution is out of date. See episode 196.
Resources
<%= javascript_include_tag :defaults %>
<div id="tasks"> <%= render :partial => 'task', :collection => @project.tasks %> </div> <p><%= add_task_link "Add a task" %></p>
<div class="task"> <% fields_for "project[task_attributes][]", task do |task_form| %> <p> Task: <%= task_form.text_field :name %> <%= link_to_function "remove", "$(this).up('.task').remove()" %> </p> <% end %> </div>
def add_task_link(name) link_to_function name do |page| page.insert_html :bottom, :tasks, :partial => 'task', :object => Task.new end end