I'm trying to implement a nested form in Padrino where I can add multiple instances of the child object using a Add whatever
button in the interface.
In Rails, one method to do this is to create a helper that generates nested fields everytime you click that Add whatever
button:
def link_to_add_fields( text, f, association, target )
new_object = f.object.class.reflect_on_association(association).klass.new
template_path = "#{association}/fields"
template = f.fields_for(association, new_object) do |builder|
render(template_path, :f => builder)
end
link_to text, "#", onclick: "add_#{association}_fields(this, \"#{escape_javascript(template)}\", \"#{target}\")"
end
However, when I try to do this in Padrino the f.fields_for (...)
block doesn't render to the template
variable, but instead is displayed in the layout.
I'm trying to find something like render_to_string
or similar in Padrino framework.
Anyone knows how to solve this? Thanks