Module: Nacho::Helper

Includes:
Common
Defined in:
lib/nacho/helper.rb

Constant Summary

Constants included from Common

Common::HTML5_ADD_NEW_VALUE_KEY, Common::HTML5_MODAL_HTML_KEY, Common::HTML5_MODAL_ID_KEY, Common::HTML5_NEW_ITEM_VALUE_KEY, Common::HTML5_OPTION_TEXT_KEY, Common::HTML5_OPTION_VALUE_KEY

Instance Method Summary collapse

Instance Method Details

#nacho_select_tag(name, choices = nil, options = {}, html_options = {}) ⇒ Object

A tag helper version for a FormBuilder class. Will create the select and the needed modal that contains the given form for the target model to create.

A multiple select will generate a button to trigger the modal.

Parameters:

Options Hash (options):

  • :include_blank (Boolean)

    Include a blank option (Forced to true when choices.count == 0)

  • :new_option_text (String)

    Text to display as the option that will trigger the new modal (Default “– Add new –”, will be ignored if html_options[:multiple] is set to true)

  • :value_key (Symbol)

    The attribute of the model that will be used as the option value from the JSON return when a new record is created

  • :text_key (Symbol)

    The attribute of the model that will be used as the option display content from the JSON return when a new record is created

  • :new_key (Symbol)

    The JSON key that will contain the value of the record that was created with the modal

  • :modal_title (String)

    The title of the modal (Default to “Add new <model.class.name>”)

  • :partial (String)

    The form partial for the modal body



23
24
25
26
27
28
29
# File 'lib/nacho/helper.rb', line 23

def nacho_select_tag(name, choices = nil, options = {}, html_options = {})
    nacho_options = build_options(name, choices, options, html_options)
    select_element = select_tag(name, options_for_select(nacho_options[:choices]), nacho_options[:options], nacho_options[:html_options])
    select_element += nacho_options[:button] if nacho_options[:html_options][:multiple]

    select_element
end