首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何运行Table_Print创业板作为独立创业板

如何运行Table_Print创业板作为独立创业板
EN

Stack Overflow用户
提问于 2016-04-29 20:35:19
回答 1查看 309关注 0票数 0

使用rails应用程序,我想利用印刷宝石,但我不允许在gem文件中安装一个新的gem。我看到有一个独立的版本,我应该能够直接安装在我的机器上,但我不知道如何使它工作。

当我调用tp Invoice.all时,我得到以下错误作为回报。

NoMethodError: main:Object的未定义方法“`tp”

我尝试过用以下代码的变体创建一个.irbrc文件,但没有joy。

代码语言:javascript
复制
# 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?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-29 21:04:06

将数组直接传递到tp参数:

代码语言:javascript
复制
 ➩ ➩  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 >

或将数组保存为变量:

代码语言:javascript
复制
 ➩ ➩  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

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

https://stackoverflow.com/questions/36947024

复制
相关文章

相似问题

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