2011-09-27 99 views
2

我正在尝试为Rails 3.1创建自定义生成器。而我写这篇:为什么'bundle install'在Rails生成器中失败?

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 

但是当我运行这个生成器(轨道摹somegem:安装,在新鲜生成的Rails应用程序),我已经收到此错误:

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. 

我发生器增加正确设计Gemfile,但在从生成器运行“bundle install”命令时失败。当我从控制台运行“捆绑安装”时,它会安装所有gem而不会出现任何错误。

这是怎么发生的?


这是我的Gemfile我跑后 '轨道摹somegem:安装'(我删除了自上市注释):

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" 
+0

请确保您在运行'bundle install'命令时连接到网络 –

回答

3

正如指出here,这是捆扎机的错误。 要使其工作:

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 
相关问题