tommy chheng
tommy chheng

Reputation: 9218

In Rails 3, how can I display the value of the error when using validation errors?

I want to display something like:

  validates :field, :inclusion => { :in => fields, :message => "is not allowed: {self.field}"}

But the self is referring to the class itself rather than the instance variable.

Upvotes: 2

Views: 258

Answers (1)

DrColossos
DrColossos

Reputation: 12998

If I understood it correctly, you want something like

class Coffee < ActiveRecord::Base
  validates_inclusion_of :size, :in => %w(small medium large),
    :message => "%{value} is not a valid size"
end

Example from the docs

Upvotes: 2

Related Questions