Custom model attribute (column name) title in Ruby on Rails

孤者浪人 提交于 2019-12-18 08:58:40

问题


Can I add custom model attribute titles, so forms could automatically render them instead of "prettied" column name?

For example I apply some method in my model, which defines attribute title:

imaginary_method_which_defines_attribute_title :description, "Aprašymas"

So I do not need to write title in every form label helper:

<%= f.label :description, "Aprašymas" %>

And form helper automatically uses attribute title which I declared in model:

<%= f.label :description %>

Renders...

<label for="foomodel_description">Aprašymas</label>

回答1:


Sounds like what you're really looking for internationalization.

Check out Rails Internationalization.

As with most things in Rails, it's a pleasure :)



来源:https://stackoverflow.com/questions/2042841/custom-model-attribute-column-name-title-in-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!