我想在Padrino中實現一個嵌套窗體,我可以在界面中使用按鈕Add whatever
來添加子對象的多個實例。如何將模板呈現給Padrino中的變量?
在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 (...)
塊沒有按」 t呈現給template
變量,但是顯示在佈局中。
我試圖在Padrino框架中找到類似render_to_string
或類似的東西。
任何人都知道如何解決這個問題?謝謝
非常感謝您的回答。我會在Padrino的Github回購上發佈一個問題,並與他們討論這個問題! – jdscosta91 2014-10-07 23:45:27