[英]Rendering a form partial block from a helper using concat
I have a helper method that inserts form fields according to arguments passed: 我有一个帮助程序方法,该方法根据传递的参数插入表单字段:
def show_json_options(form, algorithm_options)
algorithm_options.each do |o|
concat content_tag :h5, o.name
case o.selector_type
when 'input'
concat form.input o.input_name, input_html: { value: o.json_body[o.input_name] }
when 'checkbox'
concat form.input o.input_name, as: :boolean, label: o&.json_body['options']['name']
when 'multiple_checkboxes'
concat form.collection_check_boxes(o.input_name, get_multiple_options(o.json_body['options']), :first, :last)
when 'radio_buttons'
concat form.collection_radio_buttons(o.input_name, get_multiple_options(o.json_body['options']), :first, :last)
else
raise Exception.new('Unknown input.')
end
end
end
No problem whatsoever. 没问题。 However, I would like to extend the functionality of collection_radio_buttons with a block as per docs, something like: 但是,我想根据文档使用一个块扩展collection_radio_buttons的功能,例如:
<%= f.collection_radio_buttons :realm, [['External','External'], ['Internal','Internal']], :first, :last do |b| %>
<%- b.label(class: "form-control") { b.radio_button(class: "form-control") } %>
<% end %>
How would I pass these three lines into my helper method? 我如何将这三行传递到我的辅助方法中? I've tried using concat multi-line and obviously that didn't work out. 我试过使用concat多行,显然那行不通。
Couldn't figure the multiline yet, so using an inline solution for now: 尚无法确定多行,因此现在使用内联解决方案:
concat form.collection_radio_buttons o.input_name,
get_multiple_options(o.json_body['options']), :first, :last,
options = {
item_wrapper_tag: :span,
item_wrapper_class: :radio,
collection_wrapper_tag: :div,
collection_wrapper_class: :options_radio_collection
} {
|b| b.radio_button(class: "radio_buttons") + b.text
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.