使用rails应用程序,我想利用印刷宝石,但我不允许在gem文件中安装一个新的gem。我看到有一个独立的版本,我应该能够直接安装在我的机器上,但我不知道如何使它工作。
当我调用tp Invoice.all时,我得到以下错误作为回报。
NoMethodError: main:Object的未定义方法“`tp”
我尝试过用以下代码的变体创建一个.irbrc文件,但没有joy。
# Outside rails
$ irb
> require 'table_print'
> tp array_of_objects, options
# Inside rails, the gem has already been required by your Gemfile so all you need to do is
$ rails c
> tp array_of_objects, options是否有人获得了table_print的独立版本来使用rails c?
发布于 2016-04-29 21:04:06
将数组直接传递到tp参数:
➩ ➩ irb
2.0.0-p645 :002 > require 'table_print'
=> true
2.0.0-p645 :003 > tp [{id: 1, first_name: "Tim", last_name: "Thing", email: "test@example.com", dob: "1985-01-01" }, {id: 2, first_name: "Rob", last_name: "Roberts", email: "test@example.com", dob: "1985-01-01"}, {id: 3, first_name: "Nancy", last_name: "Name", email: "test@example.com", dob: "1985-01-01"}]
ID | FIRST_NAME | LAST_NAME | EMAIL | DOB
---|------------|-----------|------------------|-----------
1 | Tim | Thing | test@example.com | 1985-01-01
2 | Rob | Roberts | test@example.com | 1985-01-01
3 | Nancy | Name | test@example.com | 1985-01-01
=> 0.000762
2.0.0-p645 :004 >或将数组保存为变量:
➩ ➩ irb
2.0.0-p645 :002 > require 'table_print'
=> true
2.0.0-p645 :004 > object = [{id: 1, first_name: "Tim", last_name: "Thing", email: "test@example.com", dob: "1985-01-01" }, {id: 2, first_name: "Rob", last_name: "Roberts", email: "test@example.com", dob: "1985-01-01"}, {id: 3, first_name: "Nancy", last_name: "Name", email: "test@example.com", dob: "1985-01-01"}]
=> [{:id=>1, :first_name=>"Tim", :last_name=>"Thing", :email=>"test@example.com", :dob=>"1985-01-01"}, {:id=>2, :first_name=>"Rob", :last_name=>"Roberts", :email=>"test@example.com", :dob=>"1985-01-01"}, {:id=>3, :first_name=>"Nancy", :last_name=>"Name", :email=>"test@example.com", :dob=>"1985-01-01"}]
2.0.0-p645 :005 > tp object
ID | FIRST_NAME | LAST_NAME | EMAIL | DOB
---|------------|-----------|------------------|-----------
1 | Tim | Thing | test@example.com | 1985-01-01
2 | Rob | Roberts | test@example.com | 1985-01-01
3 | Nancy | Name | test@example.com | 1985-01-01
=> 0.001没有错误的全部跟踪,这是我所能提供的全部帮助。希望能帮上忙!
-the NoMethodError使我认为table_print不喜欢您正在传递的ActiveRecord::Relation。也许尝试将Invoice.all.map(&:attributes)传递给tp
https://stackoverflow.com/questions/36947024
复制相似问题