Module: Phlex::Rails::Helpers::OptionsForSelect

Extended by:
Phlex::Rails::HelperMacros
Defined in:
lib/phlex/rails/helpers/options_for_select.rb

Instance Method Summary collapse

Methods included from Phlex::Rails::HelperMacros

register_builder_yielding_helper, register_output_helper, register_value_helper

Instance Method Details

#options_for_select(*args, **kwargs, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/phlex/rails/helpers/options_for_select.rb', line 7

def options_for_select(*args, **kwargs, &block)
  output = if block
    view_context.options_for_select(*args, **kwargs) { |*args| capture(*args, &block) }
  else
    view_context.options_for_select(*args, **kwargs)
  end

  raw(output)

  Phlex::Rails::Never.new do
    raise Phlex::ArgumentError.new("You can’t use the return value of options_for_select as an argument to another helper in Phlex. Instead, pass a block and call options_for_select inside that block, since options_for_select outputs HTML directly. Alternatively, you can pass your options value to the select helper, skipping the options_for_select helper altogether.")
  end
end