method

submit_default_value

submit_default_value()
private

No documentation available.

# File actionpack/lib/action_view/helpers/form_helper.rb, line 1410
        def submit_default_value
          object = convert_to_model(@object)
          key    = object ? (object.persisted? ? :update : :create) : :submit

          model = if object.class.respond_to?(:model_name)
            object.class.model_name.human
          else
            @object_name.to_s.humanize
          end

          defaults = []
          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

1Note

Returns a string used for submit button label

chiperific · Apr 5, 2021

This private method returns the label used for the f.submit helper.

https://apidock.com/rails/v5.2.3/ActionView/Helpers/FormBuilder/submit

<%= form_for @post do |f| %>
<%= f.submit %>
<% end %>

In the example above, if @post is a new record, this method returns “Create Post” as submit button label; otherwise, it uses “Update Post”.

This method also checks for custom language using I18n under the helpers.submit key and using %{model} for translation interpolation:

en:
helpers:
  submit:
    create: "Create a %{model}"
    update: "Confirm changes to %{model}"

It also searches for a key specific to the given object:

en:
helpers:
  submit:
    post:
      create: "Add %{model}"