Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

you really can have default_url_options everywhere. even in mailers.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 pkg
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 rails_default_url_options.gemspec
README.md

(Rails) Default URL Options

Provide consistent application URLs across your entire codebase. Primarily useful for mailers.

Install

From the command line:

gem install rails_default_url_options

From your Gemfile:

gem 'rails_default_url_options'

Setup

This gem will automatically set up DefaultUrlOptions in a Rails web process after the first request. If you'd like to configure it manually, use an initializer.

# File: config/initializers/default_url_options.rb
DefaultUrlOptions.configure (
  case Rails.env
    when 'production'
      {
        :host     => 'app.com',
        :port     => false,     # no ports allowed in this one!
        :protocol => 'https'
      }
    when 'staging'
      {
        :host     => 'staging.app.com',
        :port     => 8080,
        :protocol => 'http'
      }
    else
      {
        :host     => '0.0.0.0',
        :port     => 3000,
        :protocol => 'http'
      }
  end
)

Tips

Want to call Rails URL helpers from the command line or anywhere in your code? Use rails_helper!

Something went wrong with that request. Please try again.