首页 文章

动态添加嵌套表单

提问于
浏览
2

我一直关注这个railscast http://media.railscasts.com/videos/074_complex_forms_part_2.mov

我有一个任务和步骤 . 每项任务都可以有很多步骤 .

我正在尝试通过单击链接添加嵌套表单 . railscast显示的内容与我所拥有的内容之间的区别在于我的步骤控制器中有我的步骤形式,但这应该不是问题 .

我也在使用带有jQuery的rails3,但是还没有看到有关如何在rails3中执行此操作的任何教程 .

我的任务/ new.html.erb

<%= form_for @task, :html=>{:multipart => true do |f| %>
  <%= render 'form', :f=>f %>
< end >

为我的任务/ _form.html.erb

<%= f.label :task_name %>
  <%= f.text_field :task_name %>

 <%= f.label :media %>
 <%= f.file_field :media %>
      < div id="steps" >
          <%= render 'steps/form', :f=> f % >
      < /div>
     <%= link_to_function "Add Step" do |page|
         page.insert_html :bottom, :steps, :partial=>'steps/form', :object => Step.new end %>
<%= f.submit %>

步骤/ form.html.erb

<p class="fields">
    <%= fields_for :steps do |builder| %>
       <%= builder.label :title >
       <%= builder.text_field :title >
       <%= builder.label :description %>
       <%= builder.text_area :description %>
    <% end %>
</p>

页面加载正常,但是当我点击“添加步骤链接”时,我收到两个javascript错误 .

RJS error:
 TypeError: Element.insert is not a function

然后

Element.insert("steps", {bottom: "<p class=\"fields\">\n\t</p>\t"});

2 回答

相关问题