0
我想使用真棒打印,而不把它放在我的rails 5應用程序中。就在控制檯中。要求在irb中的文檔不起作用。如何在不使用〜/ .irbrc文件的情況下讓awesome_print工作?
我想使用真棒打印,而不把它放在我的rails 5應用程序中。就在控制檯中。要求在irb中的文檔不起作用。如何在不使用〜/ .irbrc文件的情況下讓awesome_print工作?
這是因爲打包程序會將可用於加載的寶石隔離到您的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
謝謝Unixmonkey, 請原諒我的無知,但我不知道在哪裏可以找到.irbrc文件中的軌道5的應用程序。我是一個學習新手。 有沒有辦法使用它,而不把它放在Gemfile中? –
.irbc文件應該放在用戶的根目錄中。然後,當您在Gemfile中使用Awesomeprint創建Rails應用程序時,它將在Rails控制檯中使用。 –