Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 正在尝试查询rails数据库_Mysql_Sql_Database_Ruby On Rails 3_Activerecord - Fatal编程技术网

Mysql 正在尝试查询rails数据库

Mysql 正在尝试查询rails数据库,mysql,sql,database,ruby-on-rails-3,activerecord,Mysql,Sql,Database,Ruby On Rails 3,Activerecord,我试图从两个特定客户机的数据库中提取所有订单,我在rails c中尝试的所有操作都会给我一个错误: irb(main):008:0> clients = clients.find(name: "CLS_Trials") NoMethodError: undefined method `find' for nil:NilClass 我的模式是这样的 create_table "clients", force: true do |t| t.string "name" t.

我试图从两个特定客户机的数据库中提取所有订单,我在rails c中尝试的所有操作都会给我一个错误:

irb(main):008:0> clients = clients.find(name: "CLS_Trials")
NoMethodError: undefined method `find' for nil:NilClass
我的模式是这样的

create_table "clients", force: true do |t|
    t.string   "name"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "sku_part"
    t.float    "postage_account"
    t.boolean  "accrue_fees"
    t.float    "pick_pack_per_unit"
    t.string   "logo_file_name"
    t.string   "logo_content_type"
    t.integer  "logo_file_size"
    t.datetime "logo_updated_at"
    t.string   "slug"
    t.boolean  "sub_admin"
    t.boolean  "static_shipping"
    t.float    "static_shipping_amount"
    t.datetime "invoice_stop"
    t.string   "street_address"
    t.string   "city"
    t.string   "state"
    t.string   "zip"
    t.string   "primary_contact_name"
    t.float    "min_postage"
    t.float    "postage_threshold"
    t.integer  "pageviews_today"
    t.integer  "pageviews_yesterday"
    t.boolean  "using_analytics"
    t.string   "sites",                  default: [], array: true
    t.integer  "weather_degrees"
    t.string   "weather_status"
    t.float    "other_fees"
    t.string   "lime_light_user_name"
    t.string   "lime_light_password"
    t.boolean  "using_lime_light"
  end
我知道数据就在那里,有没有关于如何正确地为我的客户提取所有订单并将数据导出到文本文件或exel中的建议?谢谢大家!

试试这个

clients = Client.where(name: "CLS_Trials")
C为大写字母,删除尾随字母“s”。 因为ruby中的类名必须有第一个字符大写。在Rails中,模型由singular引用

编辑:

或者也可以使用内置的帮助器

clients = Client.find_by_name('CLS_Trials')
对于模型的任何属性,您都可以通过以下方式找到它们

obj = Klass_name.find_by_attr_name(attr_value)

谢谢!因此,现在要从该客户机获取所有订单,我需要做的就是,orders=orders.all(external_Id:tracking:)