初めに
railsのviewで度々見かけるが見かける度に毎回調べていたので、メモがわり。
概要
html.slim
Task.human_attribute_name(:name)
/#=> 名称
上記の形で参考書で使われていた。
前提
ja.yml
models:
task: タスク
attributes:
task:
name: 名称
config/locales/ja.ymlにおいて、このように記述がされている。
解説
html.slim
Task.human_attribute_name(:カラム名)
ja.ymlファイルの中でカラム名に対応する文字列が引っ張り出される。
ここでは'名称'がブラウザで表示されることになる。