ruby on rails - Validates uniqueness of :link -


I have a model whose name has the following validation in my model

  validates_uniqueness_of: link ,: Case_sensitive = & gt; False  

When I put "", it goes well. Now when I put "" (with a trail slatch), it is also accepted as unique but I want it to be invalid, but what is "/" in the end?

I recommend that you submit your url before submitting them in DB and before verification Slash, slash, etc.).

  validates_uniqueness_of: link ,: case_sensitive => Wrong before_validation: normalize_urls self.link.strip DRF normalize_urls! Self.link.gsub! (/ \ / $ /, '') End  

It is not enough that what you were asking, but if you do not store normalized URLs, For changes you will have to ask your DB and it can be expensive quickly.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -