Search code examples
ruby-on-railsruby-on-rails-2

Version management of gems while working with ruby on rails


I have been coding in rails3 and have all the dependencies resolved. Now, I have moved back to rails 2 and there are lots of dependency issues. Is there any sane approach to make sure that all the gems and dependencies are resolved automatically based on the current rails version?

I keep getting this error

 `default_options': undefined method `write_inheritable_attribute' for  Rails::Generator::Base:Class (NoMethodError)

Error Log

    from /home/saiesh/.rvm/gems/ruby-1.9.3-p429/gems/rails-2.3.8/lib/rails_generator/base.rb:90:in `<class:Base>'
from /home/saiesh/.rvm/gems/ruby-1.9.3-p429/gems/rails-2.3.8/lib/rails_generator/base.rb:85:in `<module:Generator>'
from /home/saiesh/.rvm/gems/ruby-1.9.3-p429/gems/rails-2.3.8/lib/rails_generator/base.rb:48:in `<module:Rails>'
from /home/saiesh/.rvm/gems/ruby-1.9.3-p429/gems/rails-2.3.8/lib/rails_generator/base.rb:6:in `<top (required)>'
from /home/saiesh/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /home/saiesh/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /home/saiesh/.rvm/gems/ruby-1.9.3-p429/gems/rails-2.3.8/lib/rails_generator.rb:37:in `<top (required)>'
from /home/saiesh/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /home/saiesh/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
from /home/saiesh/.rvm/gems/ruby-1.9.3-p429/gems/rails-2.3.8/bin/rails:15:in `<top (required)>'
from /home/saiesh/.rvm/gems/ruby-1.9.3-p429/bin/rails:19:in `load'
from /home/saiesh/.rvm/gems/ruby-1.9.3-p429/bin/rails:19:in `<main>'
from /home/saiesh/.rvm/gems/ruby-1.9.3-p429/bin/ruby_noexec_wrapper:14:in `eval'
from /home/saiesh/.rvm/gems/ruby-1.9.3-p429/bin/ruby_noexec_wrapper:14:in `<main>'

Gem List

 *** LOCAL GEMS ***

actionmailer (3.2.13, 2.3.12, 2.3.8) actionpack (3.2.13, 2.3.12, 2.3.8)
activemodel (3.2.13)
activerecord (3.2.13, 2.3.12, 2.3.8)
activeresource (3.2.13, 2.3.12, 2.3.8)
activesupport (3.2.13, 2.3.12, 2.3.8)
arel (3.0.2)
bourbon (3.0.1)
builder (3.0.4)
bundler (1.3.5)
bundler-unload (1.0.1)
cancan (1.6.10)
coffee-rails (3.2.2) coffee-script (2.2.0)
coffee-script-source (1.6.2)
commonjs (0.2.6) daemons (1.1.9)
delayed_job (3.0.5)
delayed_job_active_record (0.4.4) erubis (2.7.0)
execjs (1.4.0)
formtastic (2.2.1)
formtastic-bootstrap (2.1.3)
haml (4.0.3)
hike (1.2.3)
i18n (0.6.1)
journey (1.0.4) jquery-rails (3.0.1, 2.3.0)
json (1.8.0)
kaminari (0.14.1)
less (2.3.2)
less-rails (2.3.3)
less-rails-fontawesome (0.5.0) libv8 (3.11.8.17 x86-linux)
mail (2.5.4)
meta_search (1.1.3)
mime-types (1.23)
multi_json (1.7.7)
mysql (2.9.1) mysql2 (0.3.11)
polyamorous (0.5.0)
polyglot (0.3.3)
rack (1.4.5, 1.1.6)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (3.2.13, 2.3.8)
railties (3.2.13)
rake > (10.1.0, 10.0.4)
rdoc (4.0.1, 3.12.2)
ref (1.0.5)
rubygems-bundler (1.2.0)
rvm (1.11.3.8)
sass (3.2.9)
sass-rails (3.2.6) sprockets (2.2.2)
therubyracer (0.11.4)
thor (0.18.1)
tilt (1.4.1)
treetop (1.4.14)
twitter-bootstrap-rails (2.2.7)
tzinfo (0.3.37)
uglifier (2.1.1)


Solution

  • why not make use of gemsets for each project?

    create a file inside your app called .rvmrc

    rvm use --create ruby-x.x.x-version@your_app_name
    

    for exemple:

    rvm use --create ruby-1.9.3-head@your_app_name
    

    now when you'll run bundle it will gems to separate folder like in my case:

    .rvm/gems/ruby-1.9.3-head@your_app_name
    

    in this case switching from one app to another will load the needed gemset with gems for your app. It's like using RVM to switch between Ruby versions.