原理就是先不加载 Bundler,用 rubygems 把 pry awesome_print 等 gems 加进来以后来把 rails app 加进来。把 Rails::Console::IRB
设置成 Pry
,Hack 下 ARGV
,就可以交给 rails/commands 处理了
已经包装成 gem rails-console-pry,安装不走 bundler,如果用了 rvm gemset,需要安装到 gemset 中。顺带可以安装些 pry plugins
gem install rails-console-pry pry-doc awesome_print
然后在 rails app 根目录直接
rails-console-pry
或者进 production
环境
rails-console-pry production
需要在 Bundler 之前加载插件(就是指不在 Gemfile 中的插件)用 -r
选项
rails-console-pry -r pry-doc -r awesome_print
最好是加个 alias
alias rpry='rails-cosnole-pry -r pry-doc -r awesome_print'
出现这么大串错误了。
/Users/alpha/.rvm/gems/ruby-1.9.3-head/gems/pry-rails-0.1.6/lib/pry-rails.rb:1:in `require': cannot load such file -- pry-rails/version (LoadError)
from /Users/alpha/.rvm/gems/ruby-1.9.3-head/gems/pry-rails-0.1.6/lib/pry-rails.rb:1:in `<top (required)>'
from /Users/alpha/.rvm/gems/ruby-1.9.3-head/gems/rails-console-pry-0.0.4/bin/rails-console-pry:37:in `require'
from /Users/alpha/.rvm/gems/ruby-1.9.3-head/gems/rails-console-pry-0.0.4/bin/rails-console-pry:37:in `<top (required)>'
from /Users/alpha/.rvm/gems/ruby-1.9.3-head/bin/rails-console-pry:19:in `load'
from /Users/alpha/.rvm/gems/ruby-1.9.3-head/bin/rails-console-pry:19:in `<main>'
在 rails 项目下输入 rails-console-pry -r pry-doc -r awesome_print,看起来结果跟 rails c 的一样啊?有什么特色?我看 railscast 下的 pry 可以用 ls 命令,这个不行?
1.9.3p134 :005 > ls
NameError: undefined local variable or method ls' for main:Object
from (irb):5
from /Users/alpha/.rvm/gems/ruby-1.9.3-head/gems/railties-3.2.2/lib/rails/commands/console.rb:47:in
start'
from /Users/alpha/.rvm/gems/ruby-1.9.3-head/gems/railties-3.2.2/lib/rails/commands/console.rb:8:in start'
from /Users/alpha/.rvm/gems/ruby-1.9.3-head/gems/railties-3.2.2/lib/rails/commands.rb:41:in
'
from /Users/alpha/.rvm/gems/ruby-1.9.3-head/gems/rails-console-pry-0.0.4/bin/rails-console-pry:47:in require'
from /Users/alpha/.rvm/gems/ruby-1.9.3-head/gems/rails-console-pry-0.0.4/bin/rails-console-pry:47:in
'
from /Users/alpha/.rvm/gems/ruby-1.9.3-head/bin/rails-console-pry:19:in load'
from /Users/alpha/.rvm/gems/ruby-1.9.3-head/bin/rails-console-pry:19:in
奇怪,ls 命令之类出现这个错误?
我是这样做的:
# in .oh-my-zsh/custom/aliases.zsh
pry-rails () {
pry -I config -I ~/src/misc -e "require 'pry-rails'"
}
# ~/src/misc/pry-rails.rb
require 'environment'
require "rails/console/app"
require "rails/console/helpers"
TOPLEVEL_BINDING.eval('self').extend ::Rails::ConsoleMethods
ActiveRecord::Base.logger = Logger.new(STDOUT)
@doitian 我用的 0.0.5 也报错了
/home/ror/.rvm/gems/ruby-1.9.3-p125/gems/pry-rails-0.2.1/lib/pry-rails.rb:3:in require': cannot load such file -- pry (LoadError)
from /home/ror/.rvm/gems/ruby-1.9.3-p125/gems/pry-rails-0.2.1/lib/pry-rails.rb:3:in
'
from /home/ror/.rvm/gems/ruby-1.9.3-p125/gems/rails-console-pry-0.0.5/bin/rails-console-pry:38:in require'
from /home/ror/.rvm/gems/ruby-1.9.3-p125/gems/rails-console-pry-0.0.5/bin/rails-console-pry:38:in
'
from /home/ror/.rvm/gems/ruby-1.9.3-p125/bin/rails-console-pry:19:in load'
from /home/ror/.rvm/gems/ruby-1.9.3-p125/bin/rails-console-pry:19:in
eval'
from /home/ror/.rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:14:in
'
我有装 pry,pry-doc 等的 环境: rails 3.2.8 rvm 1.14.12 ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux] ubuntu 12.04 server