validation custom message for rails 3

Prabesh Shrestha picture Prabesh Shrestha · Mar 22, 2011 · Viewed 51.9k times · Source

Rails has introduced new way to validate attributes inside model. When I use

validates :title, :presence => true

it works but when I try to add a custom message

validates :title, :presence => true,:message => "Story title is required"

an error is generated

Unknown validator: 'message'

Answer

Shiv picture Shiv · Mar 22, 2011

Try this

validates :title, presence: { message: "Story title is required" }