【Rails4】I18nでエスケープさせない + DBのないモデルの日本語化
目的
1. 改行を含む文章をI18nで定義する
2. DBのないモデルのattributsを日本語化する
1. xxx_html で定義するとエスケープされない
# config/locales/ja.yml body_html:| 1行目<br /> 2行目 # View <%= t('body_html') %> # => # 1行目<br /> # 2行目
2. activerecordでなくてactivemodelで定義
# config/locales/ja.yml ja: activemodel: models: attributes: test: name: 名前 # Model class Test include ActiveModel::Model attr_accessor :name end # Controller def test @test = Test.new() end # View <%= form_for @test do |f| %> <%= f.file_field(:name) %> <% end %>