diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-14 00:24:30 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-14 01:07:03 +0100 |
commit | d50bf47b008ae4c1a84ccc44e8fc7633bfffa650 (patch) | |
tree | b85ac7597e6e1bc269f4cb721193aca7c2b515ee /actionpack/lib/action_view/helpers | |
parent | 8e0208f650eac23ee4b5c748d2de715344c5c629 (diff) | |
download | rails-d50bf47b008ae4c1a84ccc44e8fc7633bfffa650.tar.gz rails-d50bf47b008ae4c1a84ccc44e8fc7633bfffa650.tar.bz2 rails-d50bf47b008ae4c1a84ccc44e8fc7633bfffa650.zip |
Call :to_model before working with the object.
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 00e12bd1e9..ef1c51d4e7 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1072,16 +1072,21 @@ module ActionView @template.error_messages_for(@object_name, objectify_options(options)) end - def submit(value = nil, options = {}) - value ||= begin - key = @object ? (@object.new_record? ? :create : :update) : :submit - model = if @object.class.respond_to?(:model_name) - @object.class.model_name.human + def submit(value=nil, options={}) + value, options = nil, value if value.is_a?(Hash) + + unless value + object = @object.respond_to?(:to_model) ? @object.to_model : @object + key = object ? (object.new_record? ? :create : :update) : :submit + + model = if object.class.respond_to?(:model_name) + object.class.model_name.human else @object_name.to_s.humanize end - I18n.t(:"helpers.submit.#{key}", :model => model, :default => "#{key.to_s.humanize} #{model}") + value = I18n.t(:"helpers.submit.#{key}", :model => model, + :default => "#{key.to_s.humanize} #{model}") end @template.submit_tag(value, options.reverse_merge(:id => "#{object_name}_submit")) |