Force Ruby Version - ruby-on-rails

I just got burned because I used find_index on an array on my dev box (OSX with Ruby 1.8.7) and the deployment machine runs Ruby 1.8.6. (What's the difference between find_index and index? The latter works on 1.8.7 and 1.8.6)
So that got me thinking: what's the best way to force Rails to run with a specific Ruby version?
Since it's probably relevant (install multiple rubys!), I need to know this for OSX, but it would be useful to know for Linux, Windows, and Commodore 64 as well.
Later: Of course I'm working in a virtual appliance now, but I'd like to be able to control my Ruby versions if possible on my computer.
Note: I don't care too much disallowing Rails running with the wrong Ruby version. I'm more interested in getting the RIGHT ruby version to run. Sorry for the confusion.

This won't force the version of ruby required but you may want to utilize something like RVM to easily manage your ruby environment on your dev and production boxes.
http://rvm.io/
This allows you to easily switch and maintain multiple versions of ruby on your system.

This is brute force and ignorance, but one approach would be
raise "Wrong ruby version, please use ruby 1.8.7" unless RUBY_VERSION == "1.8.7"

Use the RUBY_VERSION constant in your Application controller.
This shows rendering the 500 error page. You would want to setup a new page in your public dir with an appropriate message.
before_filter :check_ruby_version
def check_ruby_version
unless RUBY_VERSION == "1.8.7"
render :file => File.join(Rails.public_path, '500.html'), :status => 500
end
end

Another way to look at the problem would be to be able to disregard differences in the version of Ruby you're running. My backports gem brings Ruby 1.8.6 up to date in the 1.8.x line (including the upcoming 1.8.8) and much of 1.9:
require "backports"
Or instead, for the less courageous among us, you can require only 1.8.7's features:
require "backports/1.8.7"

Related

Rails 2.3 + Ruby 1.9.3 still really slow startup

I was excited when I heard that Ruby 1.9.3 was going to halve the startup times for apps that have many, many "require" statements (such as Rails apps), compared to 1.9.2. Unfortunately, after the upgrade, the startup times for my Rails 2.3.14 app are as bad as ever. It takes 50 seconds to get to a prompt after executing "script/console". In that time, it executes 1499 "require" statements.
My question is, how do I get it to start up faster?
I used the following code snippet at the top of my environment.rb file to log all the require statements:
module Kernel
def require_new(fn)
puts "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} #{fn}"
require_old(fn)
end
alias_method :require_old, :require
alias_method :require, :require_new
end
Imho Ruby 1.9.3 is pretty slow out of the box. What could you do to improve the perfomrance is:
Apply the falcon patch if you're using p0. Here you'll find how:
https://gist.github.com/1688857
including the bonus of tuned up environment variables.
Get the freshly baked out Ruby 1.9.3-p125 http://www.ruby-lang.org/en/news/2012/02/16/ruby-1-9-3-p125-is-released/ I checked it, and my first impression is that the performance is greater than p0.
Upgrade Rails, like user shingara mentioned in the comments.

Does ruby 1.9.2 fully supports rails 2.3.x projects?

ruby 1.8.7 does not compile well under Lion and Xcode 4.2. I'd like to know whether ruby 1.9.2-p290 fully supports rails 2.3.5 and/or 2.3.11?
It's more a question if Rails is supported on Ruby 1.9.2 - but yes, it should run fine on Ruby 1.9.2 - also you need to ensure that Gems you are intending to run work on both Rails 2.3.x and Ruby 1.9.x which will be down to each gem individually.
There were some problems with the new encoding features in 1.9.2 in some older versions of rails. You should use the newest version of rails 2.3.x also for security reasons...
Another (slightly older) resource for checking out whether your associated gems might work is IsItRuby19. It hasn't been getting as much traffic as it did in the past, but when assessing whether Rails 2.x apps would work on 1.9.x Ruby, it might help flesh out the rest of your stack. It has a few notes about the Rails gem set-proper (somewhat stale), and some current notes about many other common gems.
Might save some research time or get pointers before tracking down lots of release notes.

I have a new Rails 3 app on ruby 1.8.7, what's the impact of moving to 1.9?

I'm newish to rails, and I started with rails 3 and ruby 1.8.7
I'm not sure exactly why I went with 1.8.7, but I think it was because many gems are not supported with 1.9.
Was my analysis wrong and I can move to 1.9?
What are things to consider moving to 1.9? Is rails 3 ready for it?
I've moved to 1.9.2 about two months ago and so far everything seems OK. 1.9 is largely backwards-compatible so most things are not a problem.
That said there are two possible sources of significant annoyance when going to 1.9:
CSV parsing. Ruby switched internally to FasterCSV but doing require 'fastercsv' will result in an error. This will require changes to your code if you are doing any CSV parsing.
Encoding changes. If your code (not data) includes non-ascii characters your app will fall apart. The fix is not hard, you have to put the magic comment # encoding: utf-8 on top of any such files, but again a possible source of pain.
All gems I've been using work fine (except those doing CSV).
The only real way to find out for your application is to use rvm and install 1.9.2. Upgrade all of your gems using Bundler and then run all of your tests. Manual testing of the application will ferret out any remaining issues that are not common and specific to your code and data.

Where is that modified version rails3 running on macruby?

http://www.macruby.org/blog/2010/04/30/macruby06.html
In MacRuby blog. They said that:
This release also passes about 85% of RubySpecs, is able to run a modified version of Rails 3, and implements better support for Ruby 1.9 encodings.
How can I get that modified version rails3? Google cannot give me answer.
We didn't realize the patches we made because the plan is to run vanilla Rails. Patching Rails is required because of bugs in MacRuby not behaving the same as MRI in some edge cases.

Will a standard book on ruby on rails work if I am using jRuby?

I will have to use JDBC with an old database, which I why I selected jRuby. If I get a book on ruby on rails that does not include jRuby information, will that be benficial to me?
Yes it will. Jruby is just another Ruby implementation, so pretty much everything that works in regular Ruby will work in Jruby as well. They have worked very hard at getting rails to run really well with Jruby While there are some gems that currently will not run in jruby, a Ruby On Rails book will definitely be relevant.
One thing to keep in mind though is you cannot run native (C code) gems with JRuby. However most of the popular ones have ports.

Resources