Permalink
Browse files

Allow optional link text

  • Loading branch information...
1 parent 90ed2c2 commit 229b47b702f8b2877c0ed1528f6aa891bf35cdda @rentalcustard committed Mar 28, 2012
Showing with 3 additions and 2 deletions.
  1. +3 −2 lib/ajax-nested-fields/helpers.rb
View
5 lib/ajax-nested-fields/helpers.rb
@@ -4,14 +4,15 @@ def link_to_remove_fields(name, f, container)
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this, '#{container}')")
end
- def link_to_new_child(f, association)
+ def link_to_new_child(f, association, text=nil)
+ link_text = text || "Add #{association}"
object = f.object.class.reflect_on_association(association.to_sym).klass.new
fields = f.fields_for(association, object, :child_index => "new_#{association.singularize}") do |builder|
render("#{association.singularize}_fields", :f => builder)
end
- link_to_function "Add #{association}", raw("add_child_field('#{association}', 'new_#{association.singularize}', \"#{escape_javascript(fields)}\")")
+ link_to_function link_text, raw("add_child_field('#{association}', 'new_#{association.singularize}', \"#{escape_javascript(fields)}\")")
end
end
end

0 comments on commit 229b47b

Please sign in to comment.