MIgrating development db and test db simultaneously

Posted by Eumir Gaspar on January 14, 2011 
Filed Under Ruby on Rails, Terminal tricks, Tutorial | Comments

If you’re lazy like me and don’t want to keep repeating

rails db:migrate
rails db:migrate RAILS_ENV=test

every time you create a migration, just bind them together using alias. Open up your .bash_profile(or create one if you haven’t already) and paste this:

alias migrate='rake db:migrate; rake db:migrate RAILS_ENV=test'

Now the next time you have to migrate, just type:

migrate

and you’re all set! You can also have fun and do all those other rake stuff and alias them all like rake db:seed or something.

Enjoy!

Running Thinking Sphinx, with Mysql and Postgres on OSX Snow Leopard

Posted by Eumir Gaspar on December 21, 2010 
Filed Under Bugs and Fixes, Mysq, Ruby on Rails, Thinking Sphinx, Web Development | Comments

Having installed Thinking Sphinx for a project that used postgres, I had trouble running it with mysql. I tried editing some configuration files, both for my project and even tried the global config for TS but to no avail, it kept complaining that it didn’t know the type = mysql.

This led me to think(coupled with the answer for my SO question) that I must’ve compiled my TS before specifically for postgres only so I set off to recompile said thing for both.

./configure ran fine though, but it had problems when I tried make, because it was complaining I wasn’t using the right architecture. I then realized the mysql installed in my machine was x86, when in fact what I needed was the 64-bit version.

I then downloaded the 64-bit version for macosx and installed. I then tried to make TS again and voila! It installed perfectly. Now I was itching to index my database, but a new error popped out:

ERROR: index 'prospect_delta': sql_range_query: Out of sort memory; increase server sort buffer size

Using some google-fu, I finally nailed it down to this command:

sudo mysqld_safe --key_buffer_size=16M --sort_buffer_size=1M

which sets your buffer size a bit higher for the indexing. Whew!

JRuby, WAR, and Paperclip

Posted by Christopher Rigor on March 7, 2010 
Filed Under Ruby on Rails | Comments

If you deploy a jruby on rails application as a war file, the file structure is different from a normal rails application.

|-- 404.html
|-- 422.html
|-- 500.html
|-- WEB-INF
|   |-- app
|   |-- config
|   |-- gems
|   |-- lib
|   |-- log
|   |-- tmp
|   |-- vendor
|   `-- web.xml
|-- favicon.ico
|-- images
|   `-- rails.png
|-- index.html
|-- javascripts
|   `-- application.js
|-- robots.txt
|-- stylesheets
|-- system

The rails directories are under WEB-INF while the files and directories normally on public/ are on the root directory of the j2ee web app. In glassfish, the root of a rails app named ‘labs’ is $GLASSFISH_HOME/domains/domain1/applications/j2ee-modules/labs.

Since the ‘public’ directory is not under RAILS_ROOT, you shouldn’t be using RAILS_ROOT/public when saving files. Instead, use Rails.public_path. Paperclip saves files on “:rails_root/public/system/:attachment/:id/:style/:filename” by default. You can add the :path option to change this.

has_attached_file :image, :styles => { :square => "48x48#" }, :path => "#{Rails.public_path}/system/:attachment/:id/:style/:filename"

The uploaded files should now be saved on the correct directory.

While this works, it’s probably not a good idea to save uploaded files on the j2ee-modules/ directory. When you undeploy the ‘labs’ app on glassfish, it will remove the ‘labs’ directory on j2ee-modules which includes all the uploaded files.

We can symlink labs/system to a directory outside of the glassfish directory. We can also use a different directory for paperclip which doesn’t use Rails.public_path or Rails.root. (I haven’t tested both.)

This is only an issue when deploying your jruby apps as a war file. If you’re using the glassfish gem, you don’t change the file structure at all. You just run jruby -S glassfish. If you’re using directory-based deployment on glassfish, undeploying the app doesn’t remove the directory.

Where are you saving the uploaded files? Let me know in the comments if you have other suggestions.

Running Glassfish in Server Mode

Posted by Christopher Rigor on February 24, 2010 
Filed Under Web Development | Comments

jruby --server -S glassfish -e production -p 4400

Glassfish doesn’t accept an option to run in server mode, but jruby does, so instead of using glassfish -e production, use jruby -S glassfish and add –server.

JRuby and the Glassfish Gem

Posted by Christopher Rigor on February 21, 2010 
Filed Under Ruby on Rails | Comments

The glassfish gem is another way to run a rails application in jruby. Before glassfish, I was using jruby script/server.

Using glassfish is simple. Install the gem and run jruby -S glassfish. However, I got a “missing gem” error.

$ sudo jgem install glassfish
Successfully installed glassfish-1.0.2-universal-java
1 gem installed

$ jruby -S glassfish
Starting GlassFish server at: 0.0.0.0:3000 in development environment...
Writing log messages to: /Users/crigor/labs/log/development.log.
Press Ctrl+C to stop.

Missing the Rails 2.3.4 gem. Please `gem install -v=2.3.4 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.

rails 2.3.4 is installed. In fact, jruby script/server works

$ jruby script/server
=> Booting Mongrel
=> Rails 2.3.4 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server

I checked log/development.log and found an error on the run method on config/boot.rb.

INFO: JRuby version is: 1.4.0
Feb 21, 2010 8:45:12 PM com.sun.grizzly.jruby.rack.RackApplicationPoolFactory getRackApplocationPool
SEVERE: exit
	from /Users/crigor/admoolabs/labs/config/boot.rb:38:in `run'
	from /Users/crigor/admoolabs/labs/config/boot.rb:11:in `boot!'
	from /Users/crigor/admoolabs/labs/config/boot.rb:110
	from /Users/crigor/admoolabs/labs/config/boot.rb:31:in `require'
	from /opt/local/share/java/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
	from /Users/crigor/admoolabs/labs/config/environment.rb:7
	from /Users/crigor/admoolabs/labs/config/environment.rb:31:in `require'
	from /opt/local/share/java/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
	from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/rack/adapter/rails.rb:98:in `load_application'
	from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/rack/adapter/rails.rb:75:in `initialize'
	from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/jruby/rack/rails.rb:25:in `new'
	from /opt/local/share/java/jruby/lib/ruby/gems/1.8/gems/glassfish-1.0.2-universal-java/lib/jruby/rack/rails.rb:25:in `new'
	from <script>:1

gem ‘rails’, version raised an error, thus the message “Missing the Rails 2.3.4 gem”. I’m sure that the gem is installed and jruby script/server works, so I inspected the error.

can't activate rack (~> 1.0.0, runtime) for ["actionpack-2.3.4", "rails-2.3.4"], already activated rack-1.1.0 for ["glassfish-1.0.2-universal-java"]

Look at that, it’s the familiar rubygems dependency problem. glassfish requires rack >= 0.4.0 but rubygems will activate the newest gem available which is version 1.1.0. rails 2.3.4 requires rack ~> 1.0.0, thus the conflict. This is the problem that bundler is trying to solve. Check my other post or the bundler readme for more details on the dependency problem.

The easiest way to get glassfish running is by removing rack 1.1.0. I’m not using it anyway.

$ sudo jgem uninstall rack

Select gem to uninstall:
 1. rack-1.0.1
 2. rack-1.1.0
 3. All versions
> 2
Successfully uninstalled rack-1.1.0

$ jruby -S glassfish
Starting GlassFish server at: 0.0.0.0:3000 in development environment...
Writing log messages to: /Users/crigor/admoolabs/labs/log/development.log.
Press Ctrl+C to stop.

Go to localhost:3000, click “About your application’s environment” and check development.log

Feb 21, 2010 9:03:38 PM sun.reflect.NativeMethodAccessorImpl invoke0
INFO: 

Processing Rails::InfoController#properties (for 0:0:0:0:0:0:0:1%0 at 2010-02-21 21:03:38) [GET]

Feb 21, 2010 9:03:38 PM sun.reflect.NativeMethodAccessorImpl invoke0
INFO:   SQL (28.0ms)   SELECT version FROM schema_migrations

Feb 21, 2010 9:03:38 PM sun.reflect.NativeMethodAccessorImpl invoke0
INFO: Completed in 302ms (View: 57, DB: 28) | 200 OK [http://localhost/rails/info/properties]

In the future, I will try bundler or loading the gems myself. I already tried this before with ruby 1.8.7 when rails 2.3.5 wasn’t working with bundler 0.9.4.

Please share in the comments if you have other ways of running your jruby apps. Are you using glassfish or a different java app server?

Bundler and Rubygems Again

Posted by Christopher Rigor on February 16, 2010 
Filed Under Ruby on Rails | Comments

On my previous post, I showed you how to use bundler with rails 2.3.5. Bundler is used to install the gems, and rubygems is used to load the gems. Bundler as of version 0.9.4 doesn’t work with rails 2.3.5.

Since rubygems is used to load the gems, you might still encounter dependency resolution issues. This situation is described in the readme of bundler. Let’s say you have the following gems

actionmailer 2.3.4
activemerchant 1.5.0
activesupport 2.3.5, 2.3.4

Activemerchant needs activesupport >= 2.3.2. When you require activemerchant, it will activate the latest version that meets that requirement which is 2.3.5. Actionmailer on the other hand needs activesupport = 2.3.4. When rubygems tries to activate activesupport 2.3.4, it will raise an error.

$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> gem 'activemerchant'
=> true
irb(main):003:0> gem 'actionmailer'
Gem::LoadError: can't activate activesupport (= 2.3.4, runtime) for ["actionpack-2.3.4", "actionmailer-2.3.4"], already activated activesupport-2.3.5 for ["activemerchant-1.5.0"]
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:280:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:296:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `each'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:296:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `each'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:68:in `gem'
	from (irb):3
irb(main):004:0>

Even if bundler installs the correct versions to vendor/bundler_gems, the presence of activesupport 2.3.5 in the system will cause an error. Another solution I tried is managing the load path by hand.

On config/preinitializer.rb

bundler_gems = File.expand_path('../../vendor/bundler_gems/gems', __FILE__)
if File.exist?(bundler_gems)
  Dir["#{bundler_gems}/*/lib"].each { |path| $:.unshift(path) }
end

This works if you use require instead of gem.

$ irb
irb(main):001:0> bundler_gems = File.expand_path('/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems')
=> "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems"
irb(main):002:0> if File.exist?(bundler_gems)
irb(main):003:1>   Dir["#{bundler_gems}/*/lib"].each { |path| $:.unshift(path) }
irb(main):004:1> end
=> ["/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/actionmailer-2.3.4/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/actionpack-2.3.4/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activemerchant-1.5.0/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activerecord-2.3.4/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activeresource-2.3.4/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activesupport-2.3.4/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/builder-2.1.2/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/bundler-0.9.5/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/rack-1.0.1/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/rails-2.3.4/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/rake-0.8.7/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/sqlite3-ruby-1.2.5/lib"]
irb(main):005:0> require 'rubygems'
=> true
irb(main):006:0> require 'active_merchant'
=> true
irb(main):007:0> require 'action_mailer'
=> ["MailHelper", "Text", "ActionMailer"]
$ irb
irb(main):001:0> bundler_gems = File.expand_path('/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems')
=> "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems"
irb(main):002:0> if File.exist?(bundler_gems)
irb(main):003:1>   Dir["#{bundler_gems}/*/lib"].each { |path| $:.unshift(path) }
irb(main):004:1> end
=> ["/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/actionmailer-2.3.4/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/actionpack-2.3.4/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activemerchant-1.5.0/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activerecord-2.3.4/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activeresource-2.3.4/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/activesupport-2.3.4/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/builder-2.1.2/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/bundler-0.9.5/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/rack-1.0.1/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/rails-2.3.4/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/rake-0.8.7/lib", "/Users/crigor/admoolabs/labs/vendor/bundler_gems/gems/sqlite3-ruby-1.2.5/lib"]
irb(main):005:0> require 'rubygems'
=> true
irb(main):006:0> gem 'activemerchant'
=> true
irb(main):007:0> gem 'actionmailer'
Gem::LoadError: can't activate activesupport (= 2.3.4, runtime) for ["actionpack-2.3.4", "actionmailer-2.3.4"], already activated activesupport-2.3.5 for ["activemerchant-1.5.0"]
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:280:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:296:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `each'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:296:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `each'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:295:in `activate'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems.rb:68:in `gem'
	from (irb):7
	from /opt/local/lib/ruby/1.8/i686-darwin10/rbconfig.rb:132

Require works because I added the lib/ directories to the load path. If a file exists on the load path, require will not activate the gem. It will just load the file. If gems use gem ‘activesupport’ before require ‘active_support’, then we’ll be in trouble. This is not the ideal solution I’m looking for but it’s close. On my next post, I’ll discuss using ‘fake’ rubygems.

Using Bundler 0.9.4 with Rails 2.3.5

Posted by Christopher Rigor on February 11, 2010 
Filed Under Ruby on Rails | Comments

Bundler works well with rails 3 beta but it doesn’t work with rails 2.3.5 yet. Here’s a simple way to use the gems installed by bundler.

Let’s create a rails app named labs.

$ rails labs
$ cd labs
$ ./script/console
Missing the Rails 2.3.5 gem. Please `gem install -v=2.3.5 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed

As you can see, the rails 2.3.5 gem is missing. We will use bundler to install the gems to vendor/bundler_gems.

$ vi Gemfile
source "http://gemcutter.org"
gem "rails", "2.3.5"
gem "sqlite3-ruby", :require => "sqlite3"
$ bundle install vendor/bundler_gems
Fetching source index from http://gemcutter.org
Resolving dependencies
Installing actionmailer (2.3.5) from rubygems repository at http://gemcutter.org
Installing actionpack (2.3.5) from rubygems repository at http://gemcutter.org
Installing activerecord (2.3.5) from rubygems repository at http://gemcutter.org
Installing activeresource (2.3.5) from rubygems repository at http://gemcutter.org
Installing activesupport (2.3.5) from rubygems repository at http://gemcutter.org
Installing rack (1.0.1) from rubygems repository at http://gemcutter.org
Installing rails (2.3.5) from rubygems repository at http://gemcutter.org
Installing rake (0.8.7) from rubygems repository at http://gemcutter.org
Installing sqlite3-ruby (1.2.5) from rubygems repository at http://gemcutter.org with native extensions
Your bundle is complete!
$ ./script/console
Missing the Rails 2.3.5 gem. Please `gem install -v=2.3.5 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed

The gem is still missing. Of course, the app doesn’t know where the gems are located.

We used bundler to install the gems, and in the future, we will use bundler to load the gems. Until then, we will use rubygems to load the gems. Create config/preinitializer.rb and set GEM_HOME.

$ vi config/preinitializer.rb
ENV["GEM_HOME"] = File.expand_path('../../vendor/bundler_gems', __FILE__)
$ ./script/console
Loading development environment (Rails 2.3.5)
>> Rails.version
=> "2.3.5"
>> Rack.version
=> "1.0"
>>

How I Use Bundler

Posted by Christopher Rigor on February 11, 2010 
Filed Under Ruby on Rails | Comments

You probably heard that rails 3 beta is out and you want to try it. The instructions tell you to install the gems

gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n
gem install rails --pre

Here, I’ll give you an alternative to installing rails 3 beta using bundler 0.9.3. This is for those who don’t want to mix the rails 3 gems with their system gems, or who don’t want to use rubygems. Well you still need rubygems to install bundler.

gem install bundler

After that, we create a gemfile on a directory that I’ll name ‘envs’.

$ mkdir envs
$ cd envs
$ vi Gemfile
source "http://gemcutter.org"
gem "rails", "3.0.0.beta"
$ bundle install r3b
Resolving dependencies
Installing abstract (1.0.0) from rubygems repository at http://gemcutter.org
Installing actionmailer (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing actionpack (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing activemodel (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing activerecord (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing activeresource (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing activesupport (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing arel (0.2.1) from rubygems repository at http://gemcutter.org
Installing builder (2.1.2) from rubygems repository at http://gemcutter.org
Installing bundler (0.9.3) from rubygems repository at http://gemcutter.org
Installing erubis (2.6.5) from rubygems repository at http://gemcutter.org
Installing i18n (0.3.3) from rubygems repository at http://gemcutter.org
Installing mail (2.1.2) from rubygems repository at http://gemcutter.org
Installing memcache-client (1.7.8) from rubygems repository at http://gemcutter.org
Installing mime-types (1.16) from rubygems repository at http://gemcutter.org
Installing rack (1.1.0) from rubygems repository at http://gemcutter.org
Installing rack-mount (0.4.7) from rubygems repository at http://gemcutter.org
Installing rack-test (0.5.3) from rubygems repository at http://gemcutter.org
Installing rails (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing railties (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing rake (0.8.7) from rubygems repository at http://gemcutter.org
Installing text-format (1.0.0) from rubygems repository at http://gemcutter.org
Installing text-hyphen (1.0.0) from rubygems repository at http://gemcutter.org
Installing thor (0.13.0) from rubygems repository at http://gemcutter.org
Installing tzinfo (0.3.16) from rubygems repository at http://gemcutter.org
Your bundle is complete!
$ bundle show
Gems included by the bundle:
* abstract (1.0.0)
* actionmailer (3.0.0.beta)
* actionpack (3.0.0.beta)
* activemodel (3.0.0.beta)
* activerecord (3.0.0.beta)
* activeresource (3.0.0.beta)
* activesupport (3.0.0.beta)
* arel (0.2.1)
* builder (2.1.2)
* bundler (0.9.3)
* erubis (2.6.5)
* i18n (0.3.3)
* mail (2.1.2)
* memcache-client (1.7.8)
* mime-types (1.16)
* rack (1.1.0)
* rack-mount (0.4.7)
* rack-test (0.5.3)
* rails (3.0.0.beta)
* railties (3.0.0.beta)
* rake (0.8.7)
* text-format (1.0.0)
* text-hyphen (1.0.0)
* thor (0.13.0)
* tzinfo (0.3.16)

I like to create my rails apps on a separate directory outside of envs. We need to specify the location of the Gemfile.

$ cd ..
$ bundle show
The default Gemfile was not found

We need to specify the location of the Gemfile.

$ export BUNDLE_GEMFILE="/Users/crigor/admoolabs/envs/Gemfile"
$ bundle show
Gems included by the bundle:
* abstract (1.0.0)
* actionmailer (3.0.0.beta)
* actionpack (3.0.0.beta)
...

You can now run the rails command using bundle exec.

$ rails -v
Rails 2.3.4
$ bundle exec rails -v
Rails 3.0.0.beta

Let’s create the rails app named labsapp.

$ bundle exec rails labsapp
      create
      create  README
      create  .gitignore
      create  Rakefile
      create  config.ru
      create  Gemfile
      create  app
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/models
      create  app/views/layouts
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/cookie_verification_secret.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/session_store.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  log
      create  log/server.log
      create  log/production.log
      create  log/development.log
      create  log/test.log
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/index.html
      create  public/robots.txt
      create  public/images
      create  public/images/rails.png
      create  public/stylesheets
      create  public/stylesheets/.gitkeep
      create  public/javascripts
      create  public/javascripts/application.js
      create  public/javascripts/controls.js
      create  public/javascripts/dragdrop.js
      create  public/javascripts/effects.js
      create  public/javascripts/prototype.js
      create  public/javascripts/rails.js
      create  script
      create  script/rails
      create  test
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  test/fixtures
      create  test/functional
      create  test/integration
      create  test/unit
      create  tmp
      create  tmp/sessions
      create  tmp/sockets
      create  tmp/cache
      create  tmp/pids
      create  vendor/plugins
      create  vendor/plugins/.gitkeep

Let’s run the console.

$ cd labsapp
$ ./script/rails c
Loading development environment (Rails 3.0.0.beta)
irb(main):001:0> Rails.version
=> "3.0.0.beta"
irb(main):002:0> Rack.version
=> "1.1"

You now have the rails 3 gems separate from rails 2.x gems. Only the rails 2.x gems are installed on the system.

$ gem list rails
rails (2.3.4, 2.3.2, 2.2.2, 2.1.1, 2.1.0)

uninitialized constant PGconn

Posted by Christopher Rigor on January 11, 2010 
Filed Under Ruby on Rails | Comments

I’m successfully using Postgres for development. My stack includes ruby 1.8.7, rails 2.3.4, and pg 0.8.0. One day, I get an error

NameError: uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn

I didn’t update Postgres or the pg gem so I don’t see a reason for it to stop working. Then I remember that I installed jruby and installed the activerecord adapater. Instead of using jgem install, I used gem install. This installed the gems (activerecord-jdbc-adapter, activerecord-jdbcmysql-adapter and jdbc-mysql) on my ruby 1.8.7 system. I left the gems installed thinking they wouldn’t cause any error.

So, if you encounter uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn check if you have the jdbc adapter gems for jruby.

I hope this helps someone.

Capistrano 2.5.11 Latest Release Workaround

Posted by Christopher Rigor on January 5, 2010 
Filed Under Web Development | Comments

A recent commit in Capistrano broke some of the deploys. The latest_release directory becomes the oldest release instead of the most recent. Some of the effects I’ve seen are: 1) rake db:migrate is run on the oldest release 2) deploy:cleanup deletes the most recent releases.

When you deploy, and the number of releases directories exceed keep_releases, deploy:cleanup would delete the directory that you’re trying to deploy. You’ll end up with current that symlinks to a missing directory.

You can follow the ticket on lighthouse. In the meantime, you can use a workaround. On your deploy.rb, add

set :releases, lambda { capture("ls -x #{releases_path}").split.sort }

Next Page →