I’ve been upgrading some apps and gems to the latest and greatest Rails 3. I’ve taken the time to update my ~/.bash_aliases and ~/.irbrc files to be both Rails 3 and Rails 2.x compatible. See below for the code.
~/.bash_aliases
# rails 3 shortcut 'r'
alias r='rails'
# launching console/server
sc () {
if [ -f ./script/rails ]; then
rails c $@
else
./script/console $@
fi
}
sg () {
if [ -f ./script/rails ]; then
rails g $@
else
./script/generate $@
fi
}
ss () {
if [ -f ./script/rails ]; then
rails s $@
else
./script/server $@
fi
}
sspe () {
if [ -f ./script/rails ]; then
sudo rails s -p80 $@
else
sudo ./script/server -p80 $@
fi
}
# database migrate
alias rdbm='rake db:migrate'
# tests
alias rspec='rake spec'
# rails logs, tailing and cleaning
alias tdl='tail -f ./log/development.log'
alias ttl='tail -f ./log/test.log'
alias ctl='> ./log/test.log'
alias cdl='> ./log/development.log'
~/.irbrc
require 'rubygems' rescue nil
require 'wirble'
require 'hirb'
require 'ap'
# load wirble
Wirble.init
Wirble.colorize
# load hirb
Hirb::View.enable
IRB.conf[:AUTO_INDENT] = true
if ENV.include?('RAILS_ENV')
if !Object.const_defined?('RAILS_DEFAULT_LOGGER')
require 'logger'
Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
end
def sql(query)
ActiveRecord::Base.connection.select_all(query)
end
if ENV['RAILS_ENV'] == 'test'
require 'test/test_helper'
end
# for rails 3
elsif defined?(Rails) && !Rails.env.nil?
if Rails.logger
Rails.logger =Logger.new(STDOUT)
ActiveRecord::Base.logger = Rails.logger
end
if Rails.env == 'test'
require 'test/test_helper'
end
else
# nothing to do
end
# annotate column names of an AR model
def show(obj)
y(obj.send("column_names"))
end
puts "> all systems are go wirble/hirb/ap/show <"
Note that if your’e using Bundler in your Rails app, AND use gems in your ~/.irbrc file AND attempt to start the Rails console; you’ll get errors/warnings on requiring them UNLESS you define them in your Gemfile. I use a ‘development’ group in my Gemfile for these, like so.
Gemfile
group :development do
gem "wirble"
gem "hirb"
gem "awesome_print"
end
platforms :ruby_18 do
gem 'ruby-debug'
end
platforms :ruby_19 do
gem 'ruby-debug19'
end