def commit_button(*args)
options = args.extract_options!
text = options.delete(:label) || args.shift
if @object && (@object.respond_to?(:persisted?) || @object.respond_to?(:new_record?))
if @object.respond_to?(:persisted?)
key = @object.persisted? ? :update : :create
else
key = @object.new_record? ? :create : :update
end
if @object.class.model_name.respond_to?(:human)
object_name = @object.class.model_name.human
else
object_human_name = @object.class.human_name
crappy_human_name = @object.class.name.humanize
decent_human_name = @object.class.name.underscore.humanize
object_name = (object_human_name == crappy_human_name) ? decent_human_name : object_human_name
end
else
key = :submit
object_name = @object_name.to_s.send(label_str_method)
end
text = (localized_string(key, text, :action, :model => object_name) ||
::Formtastic::I18n.t(key, :model => object_name)) unless text.is_a?(::String)
button_html = options.delete(:button_html) || {}
button_html.merge!(:class => [button_html[:class], key].compact.join(' '))
wrapper_html_class = ['commit']
wrapper_html = options.delete(:wrapper_html) || {}
wrapper_html[:class] = (wrapper_html_class << wrapper_html[:class]).flatten.compact.join(' ')
accesskey = (options.delete(:accesskey) || default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
button_html = button_html.merge(:accesskey => accesskey) if accesskey
template.content_tag(:li, Formtastic::Util.html_safe(submit(text, button_html)), wrapper_html)
end