Tuesday, 17 January 2012

Automating Rails Development Environment Startup

I'm a fan of using Window Batch to automate repetitive tasks, so put together a little script that launches all the components of my Rails development environment.

On my system, all my Rails applications are stored in a base directory, along with a folder containing the following batch scripts. To launch the development environment for a particular Rails application, I can simply supply the batch file with the name of that application.

Each batch file contains the command to launch that component:

Thursday, 12 January 2012

Starting up my Ruby on Rails Development Environment

  1. Open a command prompt and navigate to project directory.
  2. Start Spork server:
    • bundle exec spork rspec
  3. Open a second command prompt and navigate to project directory.
  4. Start Autotest:
    • bundle exec autotest
  5. Open a third command prompt and navigate to project directory.
  6. Start development server:
    • rails server
  7. Open a fourth command prompt and navigate to project directory, use this for Git operations while working.
  8. Open code IDE/text editor of choice (mine's currently Komodo Edit 6.1)
  9. Start working on RoR application!
I'm currently looking at ways to automate this startup procedure, possibly using a batch file or similar - any suggestions? Update: Post detailing startup using Windows batch scripts here

Thursday, 5 January 2012

Creating a Rails Application from Scratch

  1. Navigate to base Rails applications folder and execute:
    • rails new newAppName -T
      • The -T prevents rails generating Test::Unit files - we'll use RSpec
  2. Copy/create three required files from a base application:
    • .autotest
    • require 'autotest/growl' # enable pop-up windows
      require 'autotest/restart' # optional: forces autotest to pick the changes to this file
      require 'autotest/timestamp' # optional: shows timestamps for test runs
      require 'win32console'
      #prevent triggering when certain files modified
      Autotest.add_hook :initialize do |at|
      %w{.svn .hg .git vendor public log .idea .komodoproject .komodotools}.each {|exception| at.add_exception(exception)}
      end
      # do not clear console before running tests
      Autotest::Growl::clear_terminal = false
      view raw .autotest hosted with ❤ by GitHub
    • .gitignore
    • .bundle
      db/*.sqlite3
      log/*.log
      tmp/
      .sass-cache/
      *.log
      view raw .gitignore hosted with ❤ by GitHub
    • Gemfile
    • source 'http://rubygems.org'
      gem 'rails'
      group :development do
      gem 'sqlite3'
      gem 'rspec-rails','2.6.1'
      #annotate gem commented out as breaks deployment to Heroku. Uncomment and bundle install to use.
      #gem 'annotate',
      # :git => "git://github.com/jeremyolliver/annotate_models.git",
      # :branch => 'rake_compatibility'
      gem 'taps'
      gem 'heroku'
      gem 'therubyracer', :platform => :ruby #required for Rails 3
      end
      group :test do
      gem 'rspec-rails','2.6.1'
      gem 'webrat', '0.7.1'
      gem 'spork', '0.9.0.rc9'
      gem 'autotest' #4.4.6 or 4.2.10
      gem 'autotest-growl' #0.2.16 or 0.2.4
      gem 'autotest-rails','4.1.0'
      gem 'win32console'
      gem 'factory_girl_rails', '1.0'
      end
      group :production do
      gem 'pg'
      gem 'thin'
      end
      # Gems used only for assets and not required
      # in production environments by default.
      group :assets do
      gem 'sass-rails', '~> 3.1.4'
      gem 'coffee-rails', '~> 3.1.1'
      gem 'uglifier', '>= 1.0.3'
      end
      gem 'jquery-rails'
      # To use ActiveModel has_secure_password
      # gem 'bcrypt-ruby', '~> 3.0.0'
      # Use unicorn as the web server
      # gem 'unicorn'
      # Deploy with Capistrano
      # gem 'capistrano'
      # To use debugger
      # gem 'ruby-debug19', :require => 'ruby-debug'
      view raw Gemfile hosted with ❤ by GitHub
  3. Install new gems with:
    • bundle install