Module: ActionView::Helpers::FormHelper

Includes:
Nacho::Common
Defined in:
lib/nacho/form_builder.rb

Constant Summary

Constants included from Nacho::Common

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

Instance Method Summary collapse

Instance Method Details

#nacho_select(object_name, method, choices = nil, options = {}, html_options = {}) ⇒ Object

The helper 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



27
28
29
30
31
32
33
# File 'lib/nacho/form_builder.rb', line 27

def nacho_select(object_name, method, choices = nil, options = {}, html_options = {})
  nacho_options = build_options(method, choices, options, html_options)
  select_element = select(object_name, method, nacho_options[:choices], nacho_options[:options], nacho_options[:html_options])
  select_element += nacho_options[:button] if nacho_options[:html_options][:multiple]

  select_element
end