Force Ruby Version

I just burned out because I used find_index in an array in my dev block (OSX with Ruby 1.8.7), and the deployment machine ran Ruby 1.8.6. (What is the difference between find_index and index ? The latter works on 1.8.7 and 1.8.6)

So, I thought: what is the best way to get Rails to run a specific version of Ruby?

Since this is probably relevant (install a few rubys!), I need to know this for OSX, but it would be useful to know for Linux, Windows, and Commodore 64 too.

Later: Of course, I now work in a virtual device, but I would like to be able to control my versions of Ruby, if possible on my computer.

Note. . I don't care that Rails is working with the wrong version of Ruby. I'm more interested in starting the manual version of RIGHT. Sorry for the confusion.

+6
ruby ruby-on-rails macos
source share
4 answers

This will not necessitate the use of the required ruby ​​version, but you can use something like RVM to easily manage your ruby ​​environment in your devs and products.

http://rvm.io/

This allows you to easily switch and support multiple versions of rubies in your system.

+5
source share

This is brute force and ignorance, but one approach will be

 raise "Wrong ruby version, please use ruby 1.8.7" unless RUBY_VERSION == "1.8.7" 
+3
source share

Another way to look at the problem is to be able to ignore the differences in the version of Ruby in which you are working. My backports gem returns Ruby 1.8.6 to line 1.8.x (including the upcoming 1.8.8) and most of 1.9:

 require "backports" 

Or instead, for the less courageous among us, you can only require 1.8.7 functions:

 require "backports/1.8.7" 
+1
source share

Use the RUBY_VERSION constant in the application controller. This displays a page of 500 errors. You want to set up a new page in your public directory with the appropriate message.

before_filter: check_ruby_version

def check_ruby_version if only RUBY_VERSION == "1.8.7" render: file => File.join (Rails.public_path, '500.html'), status => 500 end end

0
source share

All Articles