简体   繁体   中英

Rails - overriding model name on submit button

I am wondering whether it is possible to override model name on create/update buttons? I am aware that is easily possible to override the whole text on the submit button, ie:

<%= f.submit "My Submit Text" %>

It is also possible to override the wording for update and create in en.yml :

en:
  helpers:
    submit:
      create: "Custom Create %{model}"
      update: "Custom Update %{model}"

But I'm not sure how to override the "model" bit, so instead of the name of the model I have some custom text (ie "action" instead of "my_action").

According to the Rails Internationalization guide , %{model} can be customized by setting the localization key for the ActiveRecord model, for example:

activerecord:
  models:
    user: Dude

You could also probably override the ActiveRecord::Base.human_attribute_name(attribute) method, but that's more work than just defining localization keys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM