0

好的,我刚刚完成了从

http://railscasts.com/episodes/196-nested-model-form-part-1

http://railscasts.com/episodes/197-nested-model-form-part-2

这些视频很棒,但现在我想自定义链接并使它们看起来像按钮......

这是链接代码:

<p><%= link_to_add_fields "Add Vehicle", f, :vehicles %></p>

这实际上链接到一个辅助方法:

  def link_to_add_fields(name, f, association)
    new_object = f.object.class.reflect_on_association(association).klass.new
    fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
      render("shipments/partials/" + association.to_s.singularize + "_fields", :f => builder)
    end
    link_to_function(name, "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")")
  end

我怎样才能把它变成一个按钮

这是我使用的按钮代码示例:

<button id="add_button" class="btn btn-primary pull-right" style="margin-right: 15px;">Add Another</button>

我试图在链接中添加一个类

试过这个:

<%= button_to_remove_fields "Remove", f, :class=>"btn btn-primary pull-right" %>

明白啦

wrong number of arguments (3 for 2)
4

1 回答 1

1
<%= link_to_remove_fields "Remove", f %>
于 2015-05-27T13:52:55.570 回答