Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"translation missing" when using validator on non-activerecord backed models #30

Closed
ghiculescu opened this issue Jun 4, 2013 · 0 comments · Fixed by #31
Closed

"translation missing" when using validator on non-activerecord backed models #30

ghiculescu opened this issue Jun 4, 2013 · 0 comments · Fixed by #31

Comments

@ghiculescu
Copy link
Contributor

I have a model that's not an ActiveRecord subclass:

class Demo
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming

  def initialize(attributes = {})
    attributes.each do |name, value|
      send("#{name}=", value)
    end
  end

  def persisted?
    false
  end

  attr_accessor :phone
  validates_plausible_phone :phone
end

It has this validator:

validates :phone, :phony_plausible => true

But I've also tried:

validates_plausible_phone :phone

Either way, when I attempt to save with an invalid phone number, the validation message displayed to the user is:

Phone translation missing: en.activemodel.errors.models.demo.attributes.phone.improbable_phone

If I use the validators on an ActiveRecord-backed model:

class User < ActiveRecord::Base
  attr_accessible :phone 
  validates_plausible_phone :phone
end

I get the correct validation message:

Phone is an invalid number

I'm happy to manually add the translation but I was just wondering if this is expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants