简体   繁体   中英

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:

<%= 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.

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
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM