Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up RVM gemset via Rails 3 template

I'm trying to set up an RVM gemset through a Rails 3 template and then, via commands in the template, start using the gemset and install the gems into the new gemset (named after the app). This does not seem to work properly. The new gems do not get installed into the gemset and in fact the gemset does not get created at all.

Here's some of the relevant code extracted from the template file:

rvmrc = <<-RVMRC
rvm_gemset_create_on_use_flag=1
rvm_trust_rvmrcs=1
rvm gemset use #{app_name}
RVMRC

create_file ".rvmrc", rvmrc

Then, further down the road:

run "cd path/to/new/app"
run 'gem install bundler --pre'
run 'bundle install'

I also tried a different version:

inside app_name do 
  run 'gem install bundler --pre'
  run 'bundle install'
end

And a third version:

inside app_name do 
  run "rvm gemset create #{app_name} && rvm gemset use #{app_name}"
  run 'gem install bundler --pre'
  run 'bundle install'
end

It works perfectly if I just cd into the new app folder in the console after the template has run. I get the RVM message: "info: Now using gemset 'test_app'." If I run the bundle install command at that point, the gems get correctly installed into the new gemset, but I can't get the same result if I just run those commands from the template file.

The log for the app generator says this:

 run    cd ~/rails3_sites/test_app from "."
 run    gem install bundler --pre from "./test_app"
 run    bundle install from "./test_app"

What am I missing? Any help is greatly appreciated. I am using ruby 1.9.2, by the way.

Thanks,

~ Andrea

like image 649
Andrea Singh Avatar asked Jan 22 '23 12:01

Andrea Singh


1 Answers

You can do it without using the rvm ruby api. Here's a snippet from our template

current_ruby = %x{rvm list}.match(/^=>\s+(.*)\s\[/)[1].strip
run "rvm gemset create #{app_name}"
run "rvm #{current_ruby}@#{app_name} gem install bundler"
run "rvm #{current_ruby}@#{app_name} -S bundle install"

file ".rvmrc", <<-END
rvm use #{current_ruby}@#{app_name}
END

This will find the current ruby selected, create a gemset with that name and then install bundler into it. Finally installs the gems specified in the Gemfile and creates an .rvmrc file.

You see the whole template in my github repository https://github.com/andyh/Template

like image 185
Andy Henson Avatar answered Feb 01 '23 19:02

Andy Henson