Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
V

validates_url

> 编程语言
Open source

URL Validation for Rails

600 stars0 likes0 views
WebsiteGitHub

About

URL Validation for Rails

Validates URL

This gem adds the capability of validating URLs to ActiveRecord and ActiveModel.

Installation

Add this to your Gemfile:

ruby
gem "validate_url"

Or install it yourself:

bash
sudo gem install validate_url

Usage

With ActiveRecord

…

With ActiveModel

ruby
class Unicorn
  include ActiveModel::Validations

  attr_accessor :homepage

  # with legacy syntax (the syntax above works also)
  validates_url :homepage, allow_blank: true
end

With RSpec

Require the matcher in spec_helper.rb or rails_helper.rb:

ruby
require 'validate_url/rspec_matcher'

In your spec:

ruby
RSpec.describe Unicorn
  it { is_expected.to validate_url_of(:homepage) }
end

I18n

The default error message is not a valid URL. You can pass the message: "my custom error" option to your validation to define your own, custom message.

Contributing

Big thanks to Tanel Suurhans, Tarmo Lehtpuu, Steve Smith and all the contributors! We appreciate all your work on new features and bugfixes.

Credits

Validates URL is created and maintained by PerfectLine, LLC.

License

Validates URL is Copyright © 2010-2014 PerfectLine, LLC. It is free software, and may be redistributed under the terms specified in the LICENSE file.

How to push a new version

  1. Bump the version number automatically:
bash
rake version:bump:patch
rake gemspec
  1. Manually update validate_url.gemspec to remove incorrect strings
  2. Update CHANGELOG.md to describe what is changing in the new version
  3. Commit and push the updated version information, gemspec and changelog to GitHub
  4. Build and push the gem to RubyGems
bash
gem build validate_url.gemspec
gem push validate_url-1.0.8.gem

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言