mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Call :to_model before working with the object.
This commit is contained in:
@@ -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"))
|
||||
|
||||
@@ -521,11 +521,11 @@ class FormHelperTest < ActionView::TestCase
|
||||
old_locale, I18n.locale = I18n.locale, :submit
|
||||
|
||||
form_for(:post) do |f|
|
||||
concat f.submit
|
||||
concat f.submit :class => "extra"
|
||||
end
|
||||
|
||||
expected = "<form action='http://www.example.com' method='post'>" +
|
||||
"<input name='commit' id='post_submit' type='submit' value='Save changes' />" +
|
||||
"<input name='commit' class='extra' id='post_submit' type='submit' value='Save changes' />" +
|
||||
"</form>"
|
||||
assert_dom_equal expected, output_buffer
|
||||
ensure
|
||||
|
||||
Reference in New Issue
Block a user