开发者

How to localize ActiveModel error messages in Rails 3?

开发者 https://www.devze.com 2023-01-18 13:44 出处:网络
class User include ActiveModel::Validations validates_presense_of :first_name validates_length_of :last_name, :in开发者_Python百科 => 3..20, :too_long => \"pick a shorter last name\", :too_short
class User
  include ActiveModel::Validations
  validates_presense_of :first_name
  validates_length_of :last_name, :in开发者_Python百科 => 3..20, :too_long => "pick a shorter last name", :too_short => "pick a longer last name"

  attr_accessor :first_name, :last_name
end

How do you

  1. localize error message(s) for :first_name
  2. localize error message(s) for :last_name


You're using a model without a database, right? You have to extend your class with the Translation Class of ActiveModel like this:

class User
  [...]
  extend ActiveModel::Translation
  [...]
0

精彩评论

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