百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
V

validates_url

> 编程语言
开源

Rails 的 URL 验证

600 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Rails 的 URL 验证

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

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