mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow f.submit to be localized per object.
This commit is contained in:
parent
e5a2a9fced
commit
a0cdfdc771
2 changed files with 33 additions and 3 deletions
|
@ -1096,6 +1096,14 @@ module ActionView
|
||||||
# create: "Create a {{model}}"
|
# create: "Create a {{model}}"
|
||||||
# update: "Confirm changes to {{model}}"
|
# update: "Confirm changes to {{model}}"
|
||||||
#
|
#
|
||||||
|
# It also searches for a key specific for the given object:
|
||||||
|
#
|
||||||
|
# en:
|
||||||
|
# helpers:
|
||||||
|
# submit:
|
||||||
|
# post:
|
||||||
|
# create: "Add {{model}}"
|
||||||
|
#
|
||||||
def submit(value=nil, options={})
|
def submit(value=nil, options={})
|
||||||
value, options = nil, value if value.is_a?(Hash)
|
value, options = nil, value if value.is_a?(Hash)
|
||||||
value ||= submit_default_value
|
value ||= submit_default_value
|
||||||
|
@ -1121,8 +1129,12 @@ module ActionView
|
||||||
@object_name.to_s.humanize
|
@object_name.to_s.humanize
|
||||||
end
|
end
|
||||||
|
|
||||||
I18n.t(:"helpers.submit.#{key}", :model => model,
|
defaults = []
|
||||||
:default => "#{key.to_s.humanize} #{model}")
|
defaults << :"helpers.submit.#{object_name}.#{key}"
|
||||||
|
defaults << :"helpers.submit.#{key}"
|
||||||
|
defaults << "#{key.to_s.humanize} #{model}"
|
||||||
|
|
||||||
|
I18n.t(defaults.shift, :model => model, :default => defaults)
|
||||||
end
|
end
|
||||||
|
|
||||||
def nested_attributes_association?(association_name)
|
def nested_attributes_association?(association_name)
|
||||||
|
|
|
@ -31,7 +31,10 @@ class FormHelperTest < ActionView::TestCase
|
||||||
:submit => {
|
:submit => {
|
||||||
:create => 'Create {{model}}',
|
:create => 'Create {{model}}',
|
||||||
:update => 'Confirm {{model}} changes',
|
:update => 'Confirm {{model}} changes',
|
||||||
:submit => 'Save changes'
|
:submit => 'Save changes',
|
||||||
|
:another_post => {
|
||||||
|
:update => 'Update your {{model}}'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -550,6 +553,21 @@ class FormHelperTest < ActionView::TestCase
|
||||||
I18n.locale = old_locale
|
I18n.locale = old_locale
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_submit_with_object_and_nested_lookup
|
||||||
|
old_locale, I18n.locale = I18n.locale, :submit
|
||||||
|
|
||||||
|
form_for(:another_post, @post) do |f|
|
||||||
|
concat f.submit
|
||||||
|
end
|
||||||
|
|
||||||
|
expected = "<form action='http://www.example.com' method='post'>" +
|
||||||
|
"<input name='commit' id='another_post_submit' type='submit' value='Update your Post' />" +
|
||||||
|
"</form>"
|
||||||
|
assert_dom_equal expected, output_buffer
|
||||||
|
ensure
|
||||||
|
I18n.locale = old_locale
|
||||||
|
end
|
||||||
|
|
||||||
def test_nested_fields_for
|
def test_nested_fields_for
|
||||||
form_for(:post, @post) do |f|
|
form_for(:post, @post) do |f|
|
||||||
f.fields_for(:comment, @post) do |c|
|
f.fields_for(:comment, @post) do |c|
|
||||||
|
|
Loading…
Reference in a new issue