Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 566205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:57:10+00:00 2026-05-13T12:57:10+00:00

I have a url field named link in my model with the following validation

  • 0

I have a url field named link in my model with the following validation

validates_uniqueness_of :link, :case_sensitive => false

When I put “http://stackoverflow.com“, it goes well.
Now when I put “https://stackoverflow.com/” (with the trailing slach), this is also accepted as unique.
But I want it to be invalid though there is “/” at the last?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:57:10+00:00Added an answer on May 13, 2026 at 12:57 pm

    I’d suggest that you normalize your URLs (add/strip trailing slash, etc. see http://en.wikipedia.org/wiki/URL_normalization) before storing them in the DB and even before validation.

    validates_uniqueness_of :link, :case_sensitive => false
    before_validation :normalize_urls
    
    def normalize_urls
      self.link.strip!
      self.link.gsub!(/\/$/,'')
    end
    

    This isn’t quite what you were asking for but if you don’t store normalized URLs, you’ll have to query your DB for all possible variations during validation and that could quickly get expensive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have URL like: http://example.com#something , how do I remove #something , without causing
I have URL scheme for my blog like this: http://www.example.com/%YEAR%/%MONTH%/%CATEGORY%/%POST_TITLE%/ Now i want to
I have url http://www.domain.com/folder/?variable=1 i would like to do a mod redirect to index.cfm
I have a field URL countryURL; in a Country class. I want to store
I have URL like this: http://localhost/PMApp/temp.htm?ProjectID=462 What I need to do is to get
Let's suppose I have the following url: /valid/django/app/path/?foo=bar&spam=eggs I can simulate a request to
I have a form field where someone can post a google maps (html) url
I have this JavaScript that adds a form field, along with a link to
I have a model called Store with a table column named website and it
I have a number of standard rails validations within my model: validates_presence_of :url_string validates_uniqueness_of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.