Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Format and validate a URL in Active Record. Example gem for RailsCasts.

tree: 3716c8c8b6

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 CHANGELOG.md
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 url_formatter.gemspec
README.md

URL Formatter Build Status

Format and validate a URL attribute in Active Record. This is an example gem created for RailsCasts episode #301.

Installation

Add to your Gemfile and run the bundle command to install it.

gem "url_formatter"

Requires Ruby 1.9.2 or later.

Usage

Call format_url in an ActiveRecord class and pass the name of the attribute you wish to format into a URL and validate.

class Comment < ActiveRecord::Base
  format_url :website
end

This will automatically add "http://" to the beginning of the website attribute upon saving if no protocol is present. It will also do validation to ensure it looks like a URL.

Development

Questions or problems? Please post them on the issue tracker. You can contribute changes by forking the project and submitting a pull request. You can ensure the tests passing by running bundle and rake.

This gem is created by Ryan Bates and is under the MIT License.

Something went wrong with that request. Please try again.