website design and development

Weblog - 10 items

View all
litespeed hosting Ruby on Rails cpanel smtp plesk port 26 email DNS spam rss IE6 float CSS gmail ActiveRecord has many through plugins news subversion migrations shell webmin mail IE7 ssl Capistrano git Flash Mac OS X ruby gems rspec cucumber Textmate Mac OS X webrat Rails 3 scope

autotest:19:in `load': no such file to load -- autotest (LoadError)

15 Feb 2011 ruby  gems

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"

15 Oct 2010 Rails 3  scope

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

05 Oct 2010 Rails 3

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

04 Oct 2010 Rails 3

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

23 Sep 2010 ActiveRecord  Ruby on 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

07 Sep 2010 Ruby on Rails

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.

08 Dec 2009 cucumber  webrat

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

18 Jun 2009 Textmate Mac OS X

Disable:
defaults write com.macromates.textmate OakProjectWindowShowTabBarEnabled false

Enable:
defaults delete com.macromates.textmate OakProjectWindowShowTabBarEnabled

Run autospec and features

16 Jun 2009 rspec  cucumber  Ruby on Rails

AUTOFEATURE=true autospec

Easy Rdoc viewing using bdoc

16 Jun 2009 ruby  gems

Install
  [sudo] gem install manalang-bdoc

Usage
  bdoc

© Level Systems 2007