Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Quick-Start Rails Server Wherever You Are

DZone's Guide to

Quick-Start Rails Server Wherever You Are

·
Free Resource
Set a workspace directory, and you can use this script to quickly launch any Rails application on port 80 by only typing the first few letters, wherever you are.

Eg. "rlaunch r" will find a project in your workspace directory that starts with "r", in this case "rails_is_awesome".


~$ rlaunch r
Loading rails_is_awesome...
** Starting Mongrel listening at 0.0.0.0:80
** Starting Rails with development environment...
** Rails loaded.


If you have more than one that starts with r, it'll show you all available projects that start with that pattern.


~$ rlaunch r
rails_is_awesome
rad_site 


Save as rlaunch, then "chmod u+x rlaunch" and put it somewhere in your path.


#!/usr/bin/env ruby
require 'abbrev'

WORKSPACE = "/Users/#{ENV['USER']}/Workspace"

begin
  entries = []
  Dir.entries(WORKSPACE).each do |f|
    entries << f if File.directory?("#{WORKSPACE}/#{f}")
  end
  entries.slice!(0, 2)
  entries= entries.abbrev
  if entries[ARGV[0]].nil?
    alternatives = []
    entries.each do |k, v|
      alternatives << v if k =~ /^#{ARGV[0]}/
    end
    alternatives.uniq!
    puts alternatives.empty? ? "No projects start with #{ARGV[0]}." : alternatives
    exit
  end
  puts "Loading #{entries[ARGV[0]]}..."
  Dir.chdir("#{WORKSPACE}/#{entries[ARGV[0]]}")
  `sudo script/server -p 80`
rescue
  puts "An error occurred."
end
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}