module FormInput::Parameter::LocaleMethods

Methods affected by localization, put in separate module for easier overloading.

Public Instance Methods

[]( name ) click to toggle source

Get value of arbitrary option. Automatically resolves call blocks.

# File lib/form_input/core.rb, line 334
def []( name )
  o = opts[ name ]
  o = instance_exec( &o ) if o.is_a?( Proc )
  o
end
format_error_message( msg, count = nil, singular = nil, plural = " click to toggle source

Format the error report message. Default implementation includes simple pluralizer. String %p in the message is automatically replaced with error title. Can be redefined to provide correctly localized error messages.

# File lib/form_input/core.rb, line 343
def format_error_message( msg, count = nil, singular = nil, plural = "#{singular}s" )
  msg = DEFAULT_ERROR_MESSAGES[ msg ] || msg.to_s
  msg += " #{count}" if count
  msg += " #{ count == 1 ? singular : plural }" if singular
  msg.gsub( '%p', error_title )
end
report( msg, *args ) click to toggle source

Report an error concerning this parameter. String %p in the message is automatically replaced with error title. In case of multiple errors, the message is added to the end of the list, making it less important than the other errors. Returns self for chaining.

# File lib/form_input/core.rb, line 354
def report( msg, *args )
  form.report( name, format_error_message( msg, *args ) ) if form
  self
end
report!( msg, *args ) click to toggle source

Report an error concerning this parameter. String %p in the message is automatically replaced with error title. In case of multiple errors, the message is added to the beginning of the list, making it more important than the other errors. Returns self for chaining.

# File lib/form_input/core.rb, line 363
def report!( msg, *args )
  form.report!( name, format_error_message( msg, *args ) ) if form
  self
end