Checking if the message header is unique with another error return - using friendly_id

So, I was trying to check first if the post header is unique before posting it. In the model, I added this line, but it doesn't do what I expected:

validates_presence_of :title, uniqueness: true

      

Of course, I can check before doing the message (in the controller) and if a message with that header exists to return an error message, but is this the correct way? I thought there might be a test for this.

0


source to share


2 answers


It should look like this:



validates :title, presence: true, uniqueness: true

      

+1


source


It should be

validates :title, uniqueness: true

      



or

validates_uniqueness_of :title

      

+1


source







All Articles