February 1, 2011

Problems with Foundation Rails 2 by Eldon Almeda

If you've been going through the Foundation Rails 2 book and ran into some problems with the sample rails apps, you're not alone. Here's some common errors I ran into and some solutions I found digging around the web.

If you have any version other than rails 2.1.0 installed, I would suggest uninstalling rails and all it's dependencies and reinstalling this version, as rails 2.1.0 seems to work best with the exercises in this book. The solutions described here apply to ruby 1.9.1 [1.9.1p430] and rails 2.1.0

If however, you do have a version of Rails > 2.1.0 [not reccomended], and you're trying to get it to work, try updating the config/environment.rb rails version to whatever of Rails you are using:

RAILS_GEM_VERSION = 'x.x.x' unless defined? RAILS_GEM_VERSION
but in this case, some of the solutions in this post may not work for you.

Problems

  1. PROBLEM: Problems related to sqlite or sqlite3.dll.

    Possible solution:

    • First, make sure you have installed the sqlite3-ruby library: 'gem install sqlite3-ruby'

      And place the sqlite.dll into ruby_installation_directory/bin folder prior to running any of the example apps

  2. PROBLEM: You run ruby script/server and get the following

    boot.rb:86:in `load_rubygems': undefined method `>=' for nil:NilClass (NoMethodError)

    Possible solution:

    • In confing/boot.rb, inside the load_rubygems method replace:
      unless (rubygems_version) = 'x.x.x'
      with
      unless (rubygems_version || Gem::RubyGemsVersion) >= '1.3.7' #or whatever gems version you have.
  3. PROBLEM: You run ruby script/server and get the following

    no such file to load -- test/unit/error (MissingSourceFile)

    Possible solution:

    • Make sure you have the test-unit library installed: 'gem install test-unit'
    • You might also want to try 'gem clean'
  4. PROBLEM: You are trying to use the
    <%= error_messages_for :post %> or a similar helper

    And you get the following message:

    {{count}} errors prohibited this {{model}} from being saved

    Possible solution:

    • It seems that the i18n library version 0.5.0 might cause problems. Try uninstalling it (gem uninstall i18n -v=0.5.0) and install the 0.4.2 version (gem install i18n -v=0.4.2).

      If you already installed Rails 2.1.0 it might complain that another library depends on i18n version 0.5.0, so in that case re-install rails 2.1.0 and all its dependencies.
    • You might also want to try 'gem clean'

My current 'gem list' command, dumps this:

actionmailer (2.1.0)
actionpack (2.1.0)
activerecord (2.1.0)
activeresource (2.1.0)
activesupport (2.1.0)
archive-tar-minitar (0.5.2)
arel (2.0.6)
builder (2.1.2)
columnize (0.3.2)
i18n (0.4.2)
ibm_db (2.5.5 mswin32)
nokogiri (1.4.4.1 x86-mingw32)
rack (1.1.0)
rails (2.1.0)
rake (0.8.7)
ruby_core_source (0.1.4)
sqlite3 (1.3.3 x86-mingw32)
sqlite3-ruby (1.3.3)
test-unit (2.1.2)
tzinfo (0.3.23)

So if you have something similar, you should hopefully be able to resolve the issues described in this post.