2017-08-10 53 views

回答

0

這是因爲打包程序會將可用於加載的寶石隔離到您的Gemfile中。

來解決這個問題,最好的辦法是將寶石添加到您的Gemfile

gem 'awesome_print', require: false, group: :development 

而在你的.irbrc,你可以require它,所以它是針對你纔會啓用:

begin 
    require 'awesome_print' 
rescue LoadError => err 
    warn "could not require awesome_print: #{err}" 
end 

但是,如果您不允許將awesome_print添加到您的資源庫中,無論出於何種原因,都有幾個黑客可以安裝gems,但不會在您的Gemfile中加載this GitHub Gist

一個這樣的例子,可以被放置在你的.irbrc的頂部:

# Add all gems in the global gemset to the $LOAD_PATH so they can be used even 
# in places like 'rails console'. 
if defined?(::Bundler) 
    global_gemset = ENV['GEM_PATH'].split(':').grep(/ruby.*@global/).first 
    $LOAD_PATH.concat(Dir.glob("#{global_gemset}/gems/*/lib")) if 
    global_gemset 
end 
+0

謝謝Unixmonkey, 請原諒我的無知,但我不知道在哪裏可以找到.irbrc文件中的軌道5的應用程序。我是一個學習新手。 有沒有辦法使用它,而不把它放在Gemfile中? –

+0

.irbc文件應該放在用戶的根目錄中。然後,當您在Gemfile中使用Awesomeprint創建Rails應用程序時,它將在Rails控制檯中使用。 –

相關問題