Class: LocaleInput

Inherits:
SimpleForm::Inputs::Base
  • Object
show all
Defined in:
app/inputs/locale_input.rb

Overview

Output HTML for a locale select form field.

The HTML generated is compatible with Bootstrap, and it prepends a flag icon (from FontAwesome) before the input.

This class is intended to be used from simple_form forms like this:

<%= simple_form_for user, wrapper: :prepend do %>
  <%= f.input :locale, as: :locale %>
  ...
<% end %>

Instance Method Summary collapse

Instance Method Details

#input(wrapper_options) ⇒ Object


15
16
17
# File 'app/inputs/locale_input.rb', line 15

def input(wrapper_options)
  "<span class=\"input-group-addon\"><i class=\"fa fa-fw fa-flag\"></i></span>#{@builder.input_field(attribute_name, collection: I18n.available_locales, label_method: lambda{|loc| locale_name loc}, selected: I18n.locale)}".html_safe
end