开发者

Why 'bundle install' fails in Rails generator?

I'm trying to create custom generator for Rails 3.1. And I wrote this:

module SomeGem
  module Generators
    class InstallGenerator < Rails::Generators开发者_运维百科::Base
      source_root File.expand_path('../templates', __FILE__)
      desc "This adds devise"

      def install
        gem "devise"
        run "bundle install"
      end
    end
  end
end

But when I run this generator (rails g somegem:install, in the fresh-generated rails app) I've get this error:

 gemfile  devise
 run      bundle install

Could not find gem 'devise (>= 0)' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.

My generator adds Devise into Gemfile properly, but it fails when run 'bundle install' command from generator. When I run 'bundle install' from console it installs all gems without any errors.

Why is this happening?


Here is my Gemfile after I run 'rails g somegem:install' (I removed comments from listing):

source 'http://rubygems.org'
source 'http://gemcutter.org'
source "http://gems.github.com"

gem 'rails', '3.1.0'
gem 'mysql2'

group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end

gem 'jquery-rails'

group :test do
  # Pretty printed test output
  gem 'turn', :require => false
end

gem 'therubyracer'
gem "devise"


As pointed here, this is a bug in Bundler. To make it work:

module SomeGem
  module Generators
    class InstallGenerator < Rails::Generators::Base
      source_root File.expand_path('../templates', __FILE__)
      desc "This adds devise"

      def install
        gem "devise"
        Bundler.with_clean_env do
          run "bundle install"
        end
      end
    end
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜