Open Rails App In Browser

This snippet will automatically open your Rails app in the browser after launch.
Icons/chart bar
Used 33 times
Created by
D Dale Zak

Usage

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/zl0s3A"
Template Source

Review the code before running this template on your machine.

inject_into_file 'config.ru', after: "run Rails.application\n" do <<-CODE
if Rails.env.development?
  Rails.application.config.after_initialize do
    port = begin
      Rails::Server::Options.new.parse!(ARGV)[:Port] || 3000
    rescue
      3000
    end
    `open http://localhost:\#{port}`
  end
end
CODE
end
Comments

Sign up or Login to leave a comment.