我在我的Rails控制台中使用Pry gem,但pry flavored rails-console似乎已经丢失了重新加载!重新加载模型和东西的方法。pry宝石如何重新加载?
以下是我开始撬控制台
c:\rails\app> pry -r ./config/environment
谢谢
我在我的Rails控制台中使用Pry gem,但pry flavored rails-console似乎已经丢失了重新加载!重新加载模型和东西的方法。pry宝石如何重新加载?
以下是我开始撬控制台
c:\rails\app> pry -r ./config/environment
谢谢
你可以在撬维基看看这个页面:https://github.com/pry/pry/wiki/Setting-up-Rails-or-Heroku-to-use-Pry
还检查了pry-rails
插件:https://github.com/rweng/pry-rails
还有很多关于该wiki中的其它内容,这是一个很好的资源。
pry-rails不会加载'reload!' –
你的意思./config/environment
?
在任何情况下,我认为这与实际启动导轨控制台不同,后者是reload!
的来源。我在我的env特定的配置文件中重新定义了IRB = Pry
,这确保了完整的控制台,并且它的所有功能都像魅力一样。
我最近写了一篇关于pry和rails的文章。你可以在这里找到它http://lucapette.com/pry/pry-everywhere/。顺便说一句,戴维已经说了,你想用撬带:
pry -r ./config/environment
,我建议你去尝试什么,我在文章中写到,它的作品真的很好。
您可以使用'RAILS_ENV = production pry -r。/ config/environment'在生产环境中使用。 –
你可以告诉撬起以载入Rails环境的.pryrc
rails = File.join Dir.getwd, 'config', 'environment.rb'
if File.exist?(rails) && ENV['SKIP_RAILS'].nil?
require rails
if Rails.version[0..0] == "2"
require 'console_app'
require 'console_with_helpers'
elsif Rails.version[0..0] == "3"
require 'rails/console/app'
require 'rails/console/helpers'
else
warn "[WARN] cannot load Rails console commands (Not on Rails2 or Rails3?)"
end
end
这将给你reload!
回来。
感谢Netmute,这从目前为止我能看到的效果最好。 –
ahhhh,重新加载!似乎正在工作,但实际上没有重新加载任何模型;然而,从班尼斯特的答案插件似乎做到了这一点 –
在Rails 3.2我还需要说'include Rails :: ConsoleMethods' – Peter
alias pryr="pry -r ./config/environment -r rails/console/app -r rails/console/helpers"
对于没有人来对这个问题最近:答案已在Rails的3.2改变了,因为他们已经改变了他们如何实现reload!
凡在早期版本的IRB命令被添加方法Object
,现在他们都加入到IRB::ExtendCommandBundle
以避免污染全局名称空间。
我现在要做的是:(1)development.rb
silence_warnings do
begin
require 'pry'
IRB = Pry
module Pry::RailsCommands ;end
IRB::ExtendCommandBundle = Pry::RailsCommands
rescue LoadError
end
end
和(2)在.pryrc
if Kernel.const_defined?("Rails") then
require File.join(Rails.root,"config","environment")
require 'rails/console/app'
require 'rails/console/helpers'
Pry::RailsCommands.instance_methods.each do |name|
Pry::Commands.command name.to_s do
Class.new.extend(Pry::RailsCommands).send(name)
end
end
end
这里的链接到Rails的拉请求,其中引入的变化 - https://github.com/rails/rails/pull/3509
pry-rails与rails的合作3.2 – tee
要使用重新加载!像铁轨控制台命令,将此代码添加到您的.pryrc
# load Rails Console helpers like reload
require 'rails/console/app'
extend Rails::ConsoleMethods
puts 'Rails Console Helpers loaded'
编辑== 宝石撬滑轨已经做到这一切的,很多simplier的。
与gem “撬”当然安装 –
如果您有宙斯和撬麻烦,尽量增加你的.pryrc
:从here
由于两者
,大家好! –