Archive for the ‘ Ruby on Rails ’ Category

Installing Rails 3 beta 2 using rvm

Rails 3 beta 2 was released at April 1. From the blog post at Riding Rails, it seems that this beta 2 break lots of things.

Note that Ruby 1.8.7 p248 and p249 has marshaling bugs that crash both Rails 2.3.x and Rails 3.0.0. Ruby 1.9.1 outright segfaults on Rails 3.0.0, so if you want to use Rails 3 with 1.9.x, jump on 1.9.2 trunk for smooth sailing.

Both Ruby 1.8.7 p248 and p249 crashed and Ruby 1.9.1 have segfaults problem. So it’s time to move on to Ruby 1.9.2. Ruby 1.9.2 is still in the development phase but it will be ready in 4 months. The scheduled release date is 31 July 2010. Let’s install rvm with ruby 1.9.2 to try out the newly released Rails 3 beta 2.

Install rvm

$ mkdir -p ~/.rvm/src && cd ~/.rvm/src && rm -rf ./rvm/ && git clone
git://github.com/wayneeseguin/rvm.git && cd rvm && ./install

The installation will take a while, and after rvm is installed, you’ll need to edit your .bashrc and .bash_profile. Append the following at the end of your .bashrc/.bash_profile:

if[[ -s /Users/stevew/.rvm/scripts/rvm ]];
    then source /Users/stevew/.rvm/scripts/rvm;
fi

Install Ruby 1.9.2 head, remember to install the head of ruby 1.9.2 branch, not the preview1 because ruby 1.9.2 preview1 doesn’t work with tzinfo gem, you will have problem like this

.rvm/gems/ruby-1.9.2-preview1/gems/tzinfo-0.3.18/lib/
tzinfo/timezone.rb:108:in `rescue in get’: protected method 
`setup’ called for #<tzinfo::datatimezone:0x000000024b7cb8> 
(TZInfo::InvalidTimezoneIdentifier)
$ rvm install 1.9.2-head

It will take a while to download and compile the ruby 1.9.2. once completed you can run the ruby command to verify the ruby version.

$ rvm 1.9.2-head
$ ruby -v
ruby 1.9.2dev (2010-04-07 trunk 27247) [x86_64-darwin10.3.0]

Set the default ruby version to ruby 1.9.2-head

$ rvm 1.9.2-head --deafult

Install Rails3 beta2, you don’t need to use sudo here to install gem beacuse all gems will install in your local home directory

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

Install sqlite/mysql gems for rails

$ gem install sqlite3-ruby
$ gem install mysql -- --with-mysql-dir=/usr/local/mysql

Just create a new project as usual and that’s it. you are now ready to try out Rails 3 beta 2.

Generating rails app in previous version after rails 3.0 beta

Rails 3.0 beta was released 2 weeks ago, rails 3 has many improvement over previous version of rails. It’s also the first version that after rails and merb merged. Truth be told, rails 3 beta has changed a lot since version 2.3.5. Many gems has not supported in rails 3 beta yet, e.g. RSpec and Cucumber. It’s hard to move your existing project to Rails 3 without the support of required gem.

As a Rails programmer, you should already grab a copy of Rails 3 beta to learn the future development of Rails. I have already installed Rails 3 beta on my Mac. Rails 3 run smoothly on new project, except RSpec and Cucumber not supported. I was able to work on existing project on Rails 2.3.5 after installed Rails 3 beta, nothing weird has happened except when I want to start a new Rails 2.3.5 project.

MyMac:work stevew$ rails _2.3.5_ rails2project
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:777:in `report_activate_error': 
RubyGem version error: railties(3.0.0.beta not = 2.3.5) (Gem::LoadError)
	from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:211:in `activate'
	from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:1056:in `gem'
	from /usr/local/bin/rails3:18:in `'

What’s wrong with my rails 2.3.5? It turns out is the problem of railties gem installed by rails 3 beta, railties gem doesn’t exists before rails 3 beta, so it complain railties version 2.3.5 not found. I start google around, and I am not alone, there is a few people out there have the same problem, and I finally found the temporary solution in the web, but I forget the link. So here is the soltion:

edit your rails script, my rails is installed at /usr/local/bin/rails, change the last 2 line to

#gem 'railties', version
#load Gem.bin_path('railties', 'rails', version)
 
gemname = 'railties'
gemname = 'rails' if version.split(".").first.to_i == 2
gem gemname, version
load Gem.bin_path(gemname, 'rails', version)

Basically, we only replace the gem name of railties to rails if the version params start with 2.

Rails 2.3.5 Released

A new version of Rails is released, Rails 2.3.5 fixed the incompatibility issues with Ruby 1.9 found in Rails 2.3.4, with Rails 2.3.5, you are not required to patch Rails if you develop your webapp using Ruby 1.9, and this release contains several bug fixes and 1 security fix. As usual, test your webapp before you upgrade and deploy your webapp in production.

RoR 2.3.4 didn’t work well with Ruby 1.9

Crack on Rails After I upgraded my macbook to snow leopard, I think it’s a good time to try out Ruby 1.9 and Rails just release version 2.3.4. I follow the installation guide on hivelogic and try to get my dirty hand on it. I think everythings should work as usual. But No. Rails 2.3.4 didn’t work well with Ruby 1.9.

No Method Error undefined method `^’ for “b”:String

The error comes from file

active_support-2.3.4/lib/active_support/message_verifier.rb

So with a little google I found others had the same issue as well, and there already have a lighthouse ticket #3144 and a patch on rails. The patch can be download from the lighthouse link.

to applied the patch

$cd /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.4 $sudo patch -p1 < /tmp/0001-ruby-1.9-friendly-secure_compare.patch

then type lib/active_support/message_verifier.rb  when it ask which file to patch, I hope the Rails team can release a quick fix to fixed this bug.