将link_to改为嵌套模型表单中的按钮



我刚刚完成了从

实现嵌套表单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)

<%= link_to_remove_fields "Remove", f %>

相关内容

  • 没有找到相关文章

最新更新