Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit 2d24aa2632c3a59c3dae3ce5680a1addc9f6f933 1 parent c20162a
@carlosantoniodasilva carlosantoniodasilva authored
View
6 lib/simple_form/form_builder.rb
@@ -203,8 +203,12 @@ def association(association, options={}, &block)
# 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
View
7 test/form_builder/button_test.rb
@@ -25,4 +25,11 @@ def with_button_for(object, *args)
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
Please sign in to comment.
Something went wrong with that request. Please try again.