Module: RailsI18nOnair::LiveUi::FormHelper
- Defined in:
- lib/rails_i18n_onair/live_ui/form_helper.rb
Overview
Prepended to ActionView::Helpers::FormBuilder so that f.submit renders a
When Live UI is OFF the call falls straight through to the original submit helper — zero overhead.
Instance Method Summary collapse
Instance Method Details
#submit(value = nil, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rails_i18n_onair/live_ui/form_helper.rb', line 10 def submit(value = nil, = {}) return super unless RailsI18nOnair::Current.live_ui_active == true # Resolve the i18n key the same way Rails' submit_default_value does, # but route through the view's t() so TranslationHelper wraps it in # an editable <span>. label = if value value else object = convert_to_model(@object) key = object ? (object.persisted? ? :update : :create) : :submit model = if object.respond_to?(:model_name) object.model_name.human else @object_name.to_s.humanize end i18n_key = if object.respond_to?(:model_name) && object_name.to_s == model.downcase "helpers.submit.#{object.model_name.i18n_key}.#{key}" else "helpers.submit.#{object_name}.#{key}" end fallback = "#{key.to_s.humanize} #{model}" # Use the view's t() which is wrapped by TranslationHelper @template.t(i18n_key, model: model, default: fallback) end = { type: "submit" }.merge() @template.content_tag(:button, label, ) end |