Skip to content

Instantly share code, notes, and snippets.

Created August 13, 2015 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f0d0666b9ef543ec1ffa to your computer and use it in GitHub Desktop.
Save anonymous/f0d0666b9ef543ec1ffa to your computer and use it in GitHub Desktop.
module ApplicationHelper
def link_to_add_fields(name, f, association)
new_object = f.object.send(association).klass.new
id = new_object.object_id
fields = f.fields_for(association, new_object, child_index: id) do |builder|
render(association.to_s.singularize + "_fields", f: builder)
end
link_to(name, '#', class: "add_fields btn btn-primary", data: {id: id, fields: fields.gsub("\n", "")})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment