Module: WrappedButton

Defined in:
lib/simple_form_extensions.rb

Instance Method Summary collapse

Instance Method Details

#wrapped_button(*args, &block) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/simple_form_extensions.rb', line 2

def wrapped_button(*args, &block)
  template. :div, class: 'form-actions' do
    options = args.extract_options!
    loading = object.new_record? ? I18n.t('simple_form.creating') : I18n.t('simple_form.updating')
    options[:"data-loading-text"] = [loading, options[:"data-loading-text"]].compact
    options[:class] = ['btn-primary', options[:class]].compact
    args << options
    cancel = options.delete(:cancel)
    if cancel
      submit(*args, &block) + ' ' + I18n.t('simple_form.buttons.or') + ' ' + template.link_to(I18n.t('simple_form.buttons.cancel'), cancel)
    else
      submit(*args, &block)
    end
  end
end