Permalink
Browse files

Added back in the deprecated formtastic methods for easier transition

Thanks to @HectorMalot for most of the code from PR #1140
  • Loading branch information...
1 parent fbc1584 commit 8f5418ec8bbe951ad3f9ef510031390516650eaa @gregbell gregbell committed Apr 25, 2012
Showing with 39 additions and 18 deletions.
  1. +39 −18 lib/active_admin/form_builder.rb
@@ -24,27 +24,14 @@ def input(method, *args)
form_buffers.last << content.html_safe
end
- # The buttons method always needs to be wrapped in a new buffer
- def buttons(*args, &block)
- content = with_new_form_buffer do
- block_given? ? super : super { commit_button_with_cancel_link }
- end
- form_buffers.last << content.html_safe
- end
-
- def commit_button(*args)
- content = with_new_form_buffer{ super }
- form_buffers.last << content.html_safe
- end
-
def cancel_link(url = nil, html_options = {}, li_attributes = {})
li_attributes[:class] ||= "cancel"
url ||= {:action => "index"}
- template.content_tag(:li, (template.link_to I18n.t('active_admin.cancel'), url, html_options), li_attributes)
+ form_buffers.last << template.content_tag(:li, (template.link_to I18n.t('active_admin.cancel'), url, html_options), li_attributes)
end
- def commit_button_with_cancel_link
- content = commit_button
+ def commit_action_with_cancel_link
+ content = action(:submit)
content << cancel_link
end
@@ -61,8 +48,8 @@ def action(*args)
end
def commit_action_with_cancel_link
- content = action(:submit)
- content << cancel_link
+ action(:submit)
+ cancel_link
end
def has_many(association, options = {}, &block)
@@ -103,6 +90,40 @@ def has_many(association, options = {}, &block)
form_buffers.last << content.html_safe
end
+ # These methods are deprecated and removed from Formtastic, however are
+ # supported here to help with transition.
+ module DeprecatedMethods
+
+ # Formtastic has depreciated #commit_button in favor of #action(:submit)
+ def commit_button(*args)
+ ::ActiveSupport::Deprecation.warn("f.commit_button is deprecated in favour of f.action(:submit)")
+
+ options = args.extract_options!
+ if String === args.first
+ options[:label] = args.first unless options.has_key?(:label)
+ end
+
+ action(:submit, options)
+ end
+
+ def commit_button_with_cancel_link
+ # Formtastic has depreciated #buttons in favor of #actions
+ ::ActiveSupport::Deprecation.warn("f.commit_button_with_cancel_link is deprecated in favour of f.commit_action_with_cancel_link")
+
+ commit_action_with_cancel_link
+ end
+
+ # The buttons method always needs to be wrapped in a new buffer
+ def buttons(*args, &block)
+ # Formtastic has depreciated #buttons in favor of #actions
+ ::ActiveSupport::Deprecation.warn("f.buttons is deprecated in favour of f.actions")
+
+ actions args, &block
+ end
+
+ end
+ include DeprecatedMethods
+
protected
def active_admin_input_class_name(as)

0 comments on commit 8f5418e

Please sign in to comment.