mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
Allow using Rails button helper with f.button :button. Closes #449
Make sure to just alias button when it is available, to avoid errors with Rails versions prior to 3.2.
This commit is contained in:
parent
c20162a49a
commit
2d24aa2632
2 changed files with 12 additions and 1 deletions
|
@ -203,8 +203,12 @@ module SimpleForm
|
|||
# f.button :submit
|
||||
# end
|
||||
#
|
||||
# It just acts as a proxy to method name given.
|
||||
# It just acts as a proxy to method name given. We also alias original Rails
|
||||
# button implementation (3.2 forward (to delegate to the original when
|
||||
# calling `f.button :button`.
|
||||
#
|
||||
# TODO: remove if condition when supporting only Rails 3.2 forward.
|
||||
alias_method :button_button, :button if method_defined?(:button)
|
||||
def button(type, *args, &block)
|
||||
options = args.extract_options!
|
||||
options[:class] = [SimpleForm.button_class, options[:class]].compact
|
||||
|
|
|
@ -25,4 +25,11 @@ class ButtonTest < ActionView::TestCase
|
|||
assert_select 'form input.btn[type=submit][value=Save Post]'
|
||||
end
|
||||
end
|
||||
|
||||
if ActionView::Helpers::FormBuilder.method_defined?(:button)
|
||||
test "allows to use Rails button helper when available" do
|
||||
with_button_for :post, :button, 'Save!'
|
||||
assert_select 'form button.button[type=submit]', 'Save!'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue