Rails Internationalization (I18n) in model validations: Possible or not?

后端 未结 3 1641
南笙
南笙 2020-12-09 07:44

I have the following validation in a model:

validates_inclusion_of :whatever, :in => [true, false], :message => I18n.t(\'please_select_whatever\')
         


        
3条回答
  •  醉话见心
    2020-12-09 08:29

    OK, iain answer works, but I took very long time to figure out where should I put the :select_whatever.

    validates_inclusion_of :whatever, :in => [true, false], :message => :select_whatever

    OK your en.yml should look like this:

    en:
      errors:
        messages:
          select_whatever: "error!!"
    

提交回复
热议问题