开发者

Where should I store form field 'hints' data?

开发者 https://www.devze.com 2023-02-17 13:02 出处:网络
Many form fields (and form builders - simple_form, formtastic) use \'Hints\' to explain more about the field. I will be using hints in the form and the show view (multiple places), so I want to store

Many form fields (and form builders - simple_form, formtastic) use 'Hints' to explain more about the field. I will be using hints in the form and the show view (multiple places), so I want to store them somewhere external to the form or view.

Is there a rails built-in way to solve this issue? If not where is the recommended place to store these hints, and relate them to the table fields? I've considered in the model itself, or in config.ym开发者_C百科l.


Why don't you store those fields in the config/locales directory? This will help you internationalize your hints using the built-in rails I18n API. Those files are YML and you will have on file per language, like:

# en.yml
en:
 forms:
   hints:
     username: Your username
#etc.

Then inside your views you will integrate those hints using: t('forms.hints.username') etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号