aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_helper.rb
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2010-01-11 23:28:47 -0200
committerJosé Valim <jose.valim@gmail.com>2010-01-14 01:07:03 +0100
commit8e0208f650eac23ee4b5c748d2de715344c5c629 (patch)
tree3902178a33edd0ed0915dd107ff1afd773c8e2c3 /actionpack/lib/action_view/helpers/form_helper.rb
parentf921ad5c97048c692859b395bc78245a343bf833 (diff)
downloadrails-8e0208f650eac23ee4b5c748d2de715344c5c629.tar.gz
rails-8e0208f650eac23ee4b5c748d2de715344c5c629.tar.bz2
rails-8e0208f650eac23ee4b5c748d2de715344c5c629.zip
Add possibility to use i18n translatios in submit FormHelper.
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb17
1 files changed, 14 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index c1f342bcdd..00e12bd1e9 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -505,7 +505,7 @@ module ActionView
# Returns a label tag tailored for labelling an input field for a specified attribute (identified by +method+) on an object
# assigned to the template (identified by +object+). The text of label will default to the attribute name unless a translation
- # is found in the current I18n locale (through helpers.label.<modelname>.<attribute>) or you specify it explicitly.
+ # is found in the current I18n locale (through helpers.label.<modelname>.<attribute>) or you specify it explicitly.
# Additional options on the label tag can be passed as a hash with +options+. These options will be tagged
# onto the HTML as an HTML element attribute as in the example shown, except for the <tt>:value</tt> option, which is designed to
# target labels for radio_button tags (where the value is used in the ID of the input tag).
@@ -1058,7 +1058,7 @@ module ActionView
def radio_button(method, tag_value, options = {})
@template.radio_button(@object_name, method, tag_value, objectify_options(options))
end
-
+
def hidden_field(method, options = {})
@emitted_hidden_id = true if method == :id
@template.hidden_field(@object_name, method, objectify_options(options))
@@ -1072,7 +1072,18 @@ module ActionView
@template.error_messages_for(@object_name, objectify_options(options))
end
- def submit(value = "Save changes", options = {})
+ 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
+ else
+ @object_name.to_s.humanize
+ end
+
+ 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"))
end