Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.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
Ruby on rails 什么';在Rails 5中实现模型多元化/单一化的正确方法是什么?_Ruby On Rails_Postgresql_Activerecord_Model_Ruby On Rails 5 - Fatal编程技术网

Ruby on rails 什么';在Rails 5中实现模型多元化/单一化的正确方法是什么?

Ruby on rails 什么';在Rails 5中实现模型多元化/单一化的正确方法是什么?,ruby-on-rails,postgresql,activerecord,model,ruby-on-rails-5,Ruby On Rails,Postgresql,Activerecord,Model,Ruby On Rails 5,我正在使用Rails5和Postgres9.5。我有这张桌子 cindex=# \d currencies; Table "public.currencies" Column | Type | Modifiers ------------+-----------------------------+------------

我正在使用Rails5和Postgres9.5。我有这张桌子

cindex=# \d currencies;
                                     Table "public.currencies"
   Column   |            Type             |                        Modifiers
------------+-----------------------------+---------------------------------------------------------
 id         | integer                     | not null default nextval('currencies_id_seq'::regclass)
 code       | character varying           |
 name       | character varying           |
 symbol     | character varying           |
 created_at | timestamp without time zone | not null
 updated_at | timestamp without time zone | not null
Indexes:
    "currencies_pkey" PRIMARY KEY, btree (id)
    "index_currencies_on_code" UNIQUE, btree (code)
然后我有这个文件,应该代表我的表

localhost:cindex davea$ cat app/models/currency.rb
class Currency < ActiveRecord::Base
end

停下来,再试一次。我不明白你的意思。什么是thsi上下文中的“spring”以及如何停止它?spring是Rails使用的预加载程序,您可以阅读它。简而言之,spring使rails能够更快地启动,但有时无法加载新文件。要停止它,请在控制台中运行
spring-stop
。您可以设置模式文件吗
db/schema.rb
我会被诅咒的——就是这样!不再出现未初始化的常量错误。停止
spring
并重试。我不明白你的意思。什么是thsi上下文中的“spring”以及如何停止它?spring是Rails使用的预加载程序,您可以阅读它。简而言之,spring使rails能够更快地启动,但有时无法加载新文件。要停止它,请在控制台中运行
spring-stop
。您可以设置模式文件吗
db/schema.rb
我会被诅咒的——就是这样!不再有未初始化的常量错误。
localhost:cindex davea$ rails console
Running via Spring preloader in process 4736
Loading development environment (Rails 5.0.4)
2.4.0 :001 > Currency.find_by_code("USD")
NameError: uninitialized constant Currency
    from (irb):1
    from /Users/davea/.rvm/gems/ruby-2.4.0/gems/railties-5.0.4/lib/rails/commands/console.rb:65:in `start'
    from /Users/davea/.rvm/gems/ruby-2.4.0/gems/railties-5.0.4/lib/rails/commands/console_helper.rb:9:in `start'
    from /Users/davea/.rvm/gems/ruby-2.4.0/gems/railties-5.0.4/lib/rails/commands/commands_tasks.rb:78:in `console'
    from /Users/davea/.rvm/gems/ruby-2.4.0/gems/railties-5.0.4/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /Users/davea/.rvm/gems/ruby-2.4.0/gems/railties-5.0.4/lib/rails/commands.rb:18:in `<top (required)>'
    from /Users/davea/Documents/workspace/cindex2/bin/rails:9:in `<top (required)>'
    from /Users/davea/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/davea/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
ActiveRecord::Schema.define(version: 20170829205136) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"

  create_table "assignments", force: :cascade do |t|
    t.integer  "user_id"
    t.integer  "role_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["role_id"], name: "index_assignments_on_role_id", using: :btree
    t.index ["user_id"], name: "index_assignments_on_user_id", using: :btree
  end

  create_table "crypto_currencies", force: :cascade do |t|
    t.string   "name"
    t.string   "symbol"
    t.bigint   "latest_market_cap_in_usd"
    t.bigint   "latest_total_supply"
    t.datetime "created_at",               null: false
    t.datetime "updated_at",               null: false
    t.index ["name", "symbol"], name: "index_crypto_currencies_on_name_and_symbol", unique: true, using: :btree
  end

  create_table "crypto_index_currencies", force: :cascade do |t|
    t.integer  "crypto_currency_id"
    t.datetime "join_date",          default: -> { "now()" }, null: false
    t.datetime "created_at",                                  null: false
    t.datetime "updated_at",                                  null: false
    t.index ["crypto_currency_id"], name: "index_crypto_index_currencies_on_crypto_currency_id", unique: true, using: :btree
  end

  create_table "crypto_index_values", force: :cascade do |t|
    t.float    "value"
    t.datetime "index_date", null: false
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["index_date"], name: "index_crypto_index_values_on_index_date", unique: true, using: :btree
  end

  create_table "crypto_prices", force: :cascade do |t|
    t.integer  "crypto_currency_id"
    t.bigint   "market_cap_usd"
    t.bigint   "total_supply"
    t.datetime "last_updated"
    t.datetime "created_at",         null: false
    t.datetime "updated_at",         null: false
    t.index ["crypto_currency_id", "last_updated"], name: "index_crypto_prices_on_crypto_currency_id_and_last_updated", unique: true, using: :btree
    t.index ["crypto_currency_id"], name: "index_crypto_prices_on_crypto_currency_id", using: :btree
  end

  create_table "currencies", force: :cascade do |t|
    t.string   "code"
    t.string   "name"
    t.string   "symbol"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["code"], name: "index_currencies_on_code", unique: true, using: :btree
  end

  create_table "roles", force: :cascade do |t|
    t.string   "name"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["name"], name: "index_roles_on_name", unique: true, using: :btree
  end

  create_table "user_notifications", force: :cascade do |t|
    t.integer "user_id"
    t.integer "crypto_currency_id"
    t.integer "price",              null: false
    t.boolean "buy",                null: false
    t.index ["crypto_currency_id"], name: "index_user_notifications_on_crypto_currency_id", using: :btree
    t.index ["user_id", "crypto_currency_id", "buy"], name: "uk_user_notifications", unique: true, using: :btree
    t.index ["user_id"], name: "index_user_notifications_on_user_id", using: :btree
  end

  create_table "users", force: :cascade do |t|
    t.string   "provider"
    t.string   "uid"
    t.string   "email"
    t.string   "first_name"
    t.string   "last_name"
    t.string   "oauth_token"
    t.date     "oauth_expires"
    t.datetime "created_at",    null: false
    t.datetime "updated_at",    null: false
    t.datetime "last_login"
  end

  add_foreign_key "assignments", "roles"
  add_foreign_key "assignments", "users"
  add_foreign_key "crypto_index_currencies", "crypto_currencies", on_delete: :cascade
  add_foreign_key "crypto_prices", "crypto_currencies", on_delete: :cascade
end