[英]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.yml中的 update和create的措辞 :
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"). 但是我不确定如何覆盖“模型”位,因此我没有一些自定义文本(例如,“操作”而不是“ my_action”),而不是模型名称。
According to the Rails Internationalization guide , %{model}
can be customized by setting the localization key for the ActiveRecord model, for example: 根据Rails国际化指南 ,可以通过设置ActiveRecord模型的本地化键来自定义
%{model}
,例如:
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. 您可能还可以重写
ActiveRecord::Base.human_attribute_name(attribute)
方法,但是这比仅仅定义本地化键ActiveRecord::Base.human_attribute_name(attribute)
更多的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.