Да, я собирался сказать - это очень старый Railscast и использует как устаревшие практики, так и старую среду. Я постараюсь помочь вам.
Макеты / application.erb
<%= javascript_include_tag :defaults %>
Проекты / new.erb
<div id="tasks">
<%= render :partial => 'task', :collection => @project.tasks %>
</div>
<p><%= add_task_link "Add a task" %></p>
Проекты / _task.erb
<div class="task">
<!-- I think this part should still work -->
<%= fields_for "project[task_attributes][]", task do |task_form| %>
<p>
Task: <%= task_form.text_field :name %>
<!-- We're going to be defining the click behavior with unobtrusive jQuery -->
<%= link_to "remove", "#", :class => 'remove_task'
</p>
<% end %>
</div>
projects_helper.rb
def add_task_link(name)
# This is a trick I picked up... if you don't feel like installing a
# javascript templating engine, or something like Jammit, but still want
# to render more than very simple html using JS, you can render a partial
# into one of the data-attributes on the element.
#
# Using Jammit's JST abilities may be worthwhile if it's something you do
# frequently though.
link_to name, "#", "data-partial" => h(render(:partial => 'task', :object => Task.new)), :class => 'add_task'
end
публичный / JavaScripts / application.js
$(function(){
// Binds to the remove task link...
$('.remove_task').live('click', function(e){
e.preventDefault();
$(this).parents('.task').remove();
});
// Add task link, note that the content we're appending
// to the tasks list comes straight out of the data-partial
// attribute that we defined in the link itself.
$('.add_task').live('click', function(e){
e.preventDefault();
$('#tasks').append($(this).data('partial'));
});
});