I’m trying to use Rails validations for a form text box to see if the text entered matches any existing values in a specific column of a table in the database. Is this possible with Rails?
Basically, like this:
User enters ‘Foobar’
Table column values: ‘Foobar,test,house,random’
Validation does not pass because ‘Foobar’ is already in the database.
Thanks!
dwmcc
You can do this in your model with something like
validates_uniqueness_of :nameor new in Rails 3 you can do multiple validations inline withvalidates :name, :presence => true, :uniqueness => trueFrom the Rails API.