首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hirb在rails控制台中完全不起作用

Hirb在rails控制台中完全不起作用
EN

Stack Overflow用户
提问于 2013-01-23 14:35:22
回答 3查看 4.2K关注 0票数 1

我遵循了hirb rdoc上的教程,但不幸的是,我的rails控制台根本无法工作。

我已经做过sudo gem install hirb

并将hirb添加到我的Gemfile中:

代码语言:javascript
复制
gem 'hirb', '~>0.7.0'

然后我启动了bundle install

我得到的结果是:

代码语言:javascript
复制
rails c
Loading development environment (Rails 3.2.11)
> require 'hirb'
=> false
> Hirb.enable
=> true
> Municipality.all
Municipality Load (0.8ms)  SELECT "municipalities".* FROM "municipalities" ORDER BY name asc
=> [#<Municipality id: 1, district_id: 6, name: "Ambalamanasy II", created_at: "2013-01-16 12:11:45", updated_at: "2013-01-16 12:11:45">,
...
# doesn't work

有人能帮上忙吗?

EN

回答 3

Stack Overflow用户

发布于 2014-08-13 20:43:04

如果你使用pry作为你的rails控制台...将此代码添加到.pryrc文件中

代码语言:javascript
复制
require 'hirb'

Hirb.enable

old_print = Pry.config.print
Pry.config.print = proc do |output, value|
  Hirb::View.view_or_page_output(value) || old_print.call(output, value)
end
票数 8
EN

Stack Overflow用户

发布于 2015-10-20 17:40:53

Yoshdog的答案是过时的-它返回一个错误:

输出错误:# NoMethodError: nil:NilClass的方法‘`pager’未定义

您可以使用updated code from the docs修复此问题

代码语言:javascript
复制
begin
  require 'hirb'
rescue LoadError
  # Missing goodies, bummer
end

if defined? Hirb
  # Slightly dirty hack to fully support in-session Hirb.disable/enable toggling
  Hirb::View.instance_eval do
    def enable_output_method
      @output_method = true
      @old_print = Pry.config.print
      Pry.config.print = proc do |*args|
        Hirb::View.view_or_page_output(args[1]) || @old_print.call(*args)
      end
    end

    def disable_output_method
      Pry.config.print = @old_print
      @output_method = nil
    end
  end

  Hirb.enable
end

这也将允许您启用/禁用Hirb,这可能会派上用场。

票数 2
EN

Stack Overflow用户

发布于 2018-12-26 16:54:05

如果你使用pry,它对我很有效

代码语言:javascript
复制
$ pwd
/Users/me/path/rails-app
$ ls -la
-rw-r--r--   1 ryosuke  staff       554 12 26 17:50 .pryrc

代码语言:javascript
复制
begin
  require 'hirb'
rescue LoadError
  # Missing goodies, bummer
end

if defined? Hirb
  # Slightly dirty hack to fully support in-session Hirb.disable/enable toggling
  Hirb::View.instance_eval do
    def enable_output_method
      @output_method = true
      @old_print = Pry.config.print
      Pry.config.print = proc do |*args|
        Hirb::View.view_or_page_output(args[1]) || @old_print.call(*args)
      end
    end

    def disable_output_method
      Pry.config.print = @old_print
      @output_method = nil
    end
  end

  Hirb.enable
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14473802

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档