Bry*_*yce 0 ruby-on-rails-3 simple-form
我正在创建一个自定义的SimpleForm输入.它利用javascript模式弹出窗口来选择值.
如果我在表单视图中包含模态部分,我基本上可以使它工作,但我希望自定义输入将部分推送到模板.
但是,我无法让它发挥作用.我正在尝试这个,但它没有正确地呈现部分.
class ProductCategoryImageSelectInput < SimpleForm::Inputs::CollectionSelectInput
def input
html = ''
html << '<a href="#myModal" role="button" data-toggle="modal">Launch demo modal</a>'
File.open("#{Rails.root}/app/views/product_categories/_browse_modal.html.erb", 'r') do |f|
html << f.read
end
end
end
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
编辑
我显然对于发布屏幕截图的用户来说太新了,但这里是功能差异的链接:
当我在表单中嵌入模态代码时,我得到了这个,这是所需的功能: 工作
当我尝试将模态代码放在自定义输入中时,我得到了这个: 不工作
小智 6
您还可以使用SimpleForm::FormBuilder分配给名为的实例变量的实例从自定义输入呈现部分@builder:
class ProductCategoryImageSelectInput < SimpleForm::Inputs::CollectionSelectInput
def input
@builder.template.render(partial: 'product_categories/browse_modal', locals: { foo: 'bar'})
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
706 次 |
| 最近记录: |