Created
July 17, 2020 17:04
-
-
Save LucasKuhn/845d3b8f7b6c0767f9fc1ea019a353d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def submit(value = nil, options = {}) | |
# ... | |
value ||= submit_default_value | |
# ... | |
end | |
def submit_default_value | |
object = convert_to_model(@object) | |
key = object ? (object.persisted? ? :update : :create) : :submit | |
model = if object.respond_to?(:model_name) | |
object.model_name.human | |
else | |
@object_name.to_s.humanize | |
end | |
defaults = [] | |
# Object is a model and it is not overwritten by as and scope option. | |
if object.respond_to?(:model_name) && object_name.to_s == model.downcase | |
defaults << :"helpers.submit.#{object.model_name.i18n_key}.#{key}" | |
else | |
defaults << :"helpers.submit.#{object_name}.#{key}" | |
end | |
defaults << :"helpers.submit.#{key}" | |
defaults << "#{key.to_s.humanize} #{model}" | |
I18n.t(defaults.shift, model: model, default: defaults) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment