0
0

More than 3 years have passed since last update.

human_attribute_name(:カラム名)を使う Rails

Posted at

初めに

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ファイルの中でカラム名に対応する文字列が引っ張り出される。
ここでは'名称'がブラウザで表示されることになる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0