0

Ok i just got done implementing a nested Form from

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

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

These videos are great but now i want to customize the links and make them look like buttons...

this is the link code:

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

and that actually links to a helper method:

  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

how can i make this into a button

Here is a sample of a button code that i use:

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

I Have tried to add a class to the link

Tried this:

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

Got This

wrong number of arguments (3 for 2)
Big Al Ruby Newbie
  • 834
  • 1
  • 10
  • 30

1 Answers1

1
<%= link_to_remove_fields "Remove", f %>
Vrushali Pawar
  • 3,753
  • 1
  • 13
  • 22
  • I did forget the Arrow now i get `wrong number of arguments (3 for 2)` – Big Al Ruby Newbie May 27 '15 at 13:54
  • try to give that class to p tag – Vrushali Pawar May 27 '15 at 13:56
  • that works please update your answer and i will accept thanks... didnt know i could change a p tag into a button looking element – Big Al Ruby Newbie May 27 '15 at 13:59
  • try this .button { display: inline-block; outline: none; cursor: pointer; border: solid 1px #da7c0c; background: #478dad; text-align: center; text-decoration: none; font: 14px/100% Arial, Helvetica, sans-serif; padding: .5em 2em .55em; text-shadow: 0 1px 1px rgba(0,0,0,.3); -webkit-border-radius: .5em; -moz-border-radius: .5em; border-radius: .3em; -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2); -moz-box-shadow: 0 1px 2px rgba(0,0,0,.2); box-shadow: 0 1px 2px rgba(0,0,0,.2); } and give this class to p tag – Vrushali Pawar May 27 '15 at 14:07