Running Bundler from Application Template

Simple app template:

gem 'faker'
run "bundle install"

When I run it: rails new test_app -m /path/to/my/template.rb

It doesn't install the gem. Just fails silently.

Any ideas?

I am using ruby 1.9.2 and RVM

pimpmaster wrote:

Simple app template:

gem 'faker'
run "bundle install"

When I run it: rails new test_app -m /path/to/my/template.rb

It doesn't install the gem. Just fails silently.

Any ideas?

I am using ruby 1.9.2 and RVM

Do you have a Gemfile in place?

Hi,

Assuming you have bundler installed, try changing the line to run the
bundle install command in your template to this:

inside app_name do
  run 'bundle install'
end

You need to make sure you are in the directory of your new rails app
that has the Gemfile for the "bundle install" command to run correctly.

Hope this works.

~ Andrea

http://blog.madebydna.com

Hmm, as I understand it, all the commands are already run from
Rails.root. I tried your suggestion and the outcome was the same.

Here is a script I am testing out, for a clearer idea

http://github.com/activestylus/rails3_mongoid_template/raw/master/test_initialize.rb

A few things are just wrong here. I can successfully create the rvm
gemset and install gems BUT

1. The gems are installed into the global gemset, even though I
clearly run "rvm use 1.9.2@my_app"
2. run "bundle install" has absolutely no effect.

At first I thought bundler might be the trouble, but since RVM also
behaves flaky, it has to be an inherent problem with rails templates,
or even thor. I will be posting issues on the github repo to see if I
can get to the bottom of this.

My ultimate plan is to basically have a template that will not only
generate the rails app I want, but also install the gems, run all
installers/generators so I have a fully functioning environment right
out of the box.

PS - Nice blog, I tried to add you to my RSS reader but that link only
returns the XML as raw source, instead of triggering the reader..
weird.

Also, was it you who posted this?
http://stackoverflow.com/questions/3604077/setting-up-rvm-gemset-via-rails-3-template

seems like a variety of approaches have been tried, with no luck.

Hi,

Yes, the post on stackoverflow was indeed mine. The thing is that I had
given up on getting the RVM commands to run from the template, but I
have recently revisited the problem and finally figured it out.

It turns out that in order to hit the RVM shell from a ruby file you
need to go through the RVM ruby API. You can find the API code in your
.rvm/lib folder.

By digging around in the API, I managed to create a new Gemset for a
particular RVM ruby version, start using the Gemset, install bunder and
rails and finally run the command to create a new rails app using a
template.

When I saw your post yesterday I was coincidentally in the process of
finishing up a blog post on this very topic. It is now online at:

http://blog.madebydna.com/cooking-up-a-custom-rails-3-template

The code for my template is available on github. It might more than what
you need, but as explained in the blog post it can be easily customized.

http://github.com/madebydna/rails-templater

Best,

Andrea