Weblog - 10 items
autotest:19:in `load': no such file to load -- autotest (LoadError)
After upgrading ruby gems to verions 1.5.2
and then upgrading bundler
Autotest no longer worked.
Giving the following error.
autotest:19:in `load': no such file to load -- autotest (LoadError)
For the moment the only fix I could find is to dowgrade bundler and ruby gems again.
If you know the ruby gems version you are downgrading to then this will work
sudo gem update --system 1.3.7
otherwise try
sudo gem uninstall -v '1.5.2' rubygems-update
sudo gem update --system --local
Rails 3 lambda in scope "odd number list for Hash"
In Rails 3 using lambda in a scope only requires 1 set of curly brackets.
eg.
Rails 2.3.x
named_scope :current_language, lambda { { :conditions => ["posts.language_id = ? ", @language.id] } }
Rails 3
scope :current_language, lambda { where("posts.language_id = ? ", @language.id) }
Rails 3 - bundler: command not found: rspec
I am upgrading an app to Rails 3 and on to getting the rspec specs running.
After installing the compatible verison of rspec and running bundle install etc.
rake spec
I get this
bundler: command not found: rspec
Install missing gem binaries with `bundle install`
I am using Ruby Enterprise locally and there was a executable that was not being found.
/opt/ruby-enterprise-1.8.7-2010.01/bin/rspec
on symlinking to this executable from the necessary bin directory the problem was solved.
sudo ln -s /opt/ruby-enterprise-1.8.7-2010.01/bin/rspec /usr/local/bin/rspec
Rails 3 reload plugin or engine
If you have a plugin or engine that you would like to reload on each page call in development mode.
In rails 2 this was done by:
if RAILS_ENV == 'development'
ActiveSupport::Dependencies.load_once_paths.reject!{|x| x =~
/^#{Regexp.escape(File.dirname(__FILE__))}/}
end
In rails 3 use:
if RAILS_ENV == 'development'
ActiveSupport::Dependencies.autoload_once_paths.reject!{|x| x =~
/^#{Regexp.escape(File.dirname(__FILE__))}/}
end
ActiveRecord ruby Script without Rails
Below is an example script of how to use existing ActiveRecord Models in a rails app without loading the entire rails app.
#!/usr/bin/env ruby
require 'rubygems'
require 'active_record'
require 'yaml'
RAILS_ROOT = File.join(File.expand_path(File.dirname(__FILE__)), '..')
puts RAILS_ROOT
dbconfig = YAML::load(File.open("#{RAILS_ROOT}/config/database.yml"))
ActiveRecord::Base.establish_connection(dbconfig["development"])
require "#{RAILS_ROOT}/app/models/site"
Site.all.each do |site|
puts site.domain
end
rails show mysql log in script/console
After starting script/console
run the following as the first command
ActiveRecord::Base.logger = Logger.new(STDOUT)
Cucumber / webrat not following redirects between multiple domains.
When you need to test using multiple domains in one app and you need to redirect between those domains Webrat does not follow the redirects as it considers them to be a redirect to an external app.
A fix is to set the following in your support/env.rb file so that internal_redirect? returns true in such a case. Of course if you are actually redirecting to an external app it might cause other issues.
class Webrat::Session
alias internal_redirect? redirect?
end
Enable and disable tabs in Textmate
Disable:
defaults write com.macromates.textmate OakProjectWindowShowTabBarEnabled false
Enable:
defaults delete com.macromates.textmate OakProjectWindowShowTabBarEnabled
Run autospec and features
AUTOFEATURE=true autospec
Easy Rdoc viewing using bdoc
Install
[sudo] gem install manalang-bdoc
Usage
bdoc
