【发布时间】:2014-10-03 15:21:13
【问题描述】:
我正在尝试在 Padrino 中实现一个嵌套表单,我可以在其中使用界面中的 Add whatever 按钮添加子对象的多个实例。
在 Rails 中,一种方法是创建一个帮助程序,每次单击 Add whatever 按钮时生成嵌套字段:
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
但是,当我尝试在 Padrino 中执行此操作时,f.fields_for (...) 块不会渲染到 template 变量,而是显示在布局中。
我试图在 Padrino 框架中找到类似 render_to_string 或类似的东西。
有人知道如何解决这个问题吗?谢谢
【问题讨论】:
标签: ruby-on-rails nested-forms padrino form-helpers