gpt4 book ai didi

ruby-on-rails - RubyMine 错误 : Unable to find associated Rails Model for ':users' associations failed

转载 作者:数据小太阳 更新时间:2023-10-29 07:46:15 26 4
gpt4 key购买 nike

我正在编写一些教程,但遇到了一些问题。 RubyMine 无法为“:users”关联找到关联的 Rails 模型失败

我正在使用:
- ruby 矿 7
- Ruby 版本 meneger (rvm)
- ruby​​-1.9.3-p551 [x86_64]
- ruby​​-2.1.5 [x86_64]
- rails Rails 4.1.8

- gem sqllite3

我的模型是:

class Company < ActiveRecord::Base
has_many :users
has_many :projects
end

class Project < ActiveRecord::Base
belongs_to :company
has_many :works
has_many :users, :through => :works
end

class User < ActiveRecord::Base
belongs_to :company
has_many :works
has_many :projects, :through => :works
end

class Work < ActiveRecord::Base
belongs_to :project
belongs_to :user
end

enter image description here

Shema.rb

ActiveRecord::Schema.define(version: 20141207111312) do

create_table "companies", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "projects", force: true do |t|
t.string "name"
t.integer "company_id"
t.integer "default_rate"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "users", force: true do |t|
t.string "fname"
t.string "lname"
t.integer "company_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end

add_index "users", ["user_id"], name: "index_users_on_user_id"

create_table "works", force: true do |t|
t.integer "project_id"
t.integer "user_id"
t.datetime "datetimeperformed"
t.decimal "hours", precision: 5, scale: 2
t.datetime "created_at"
t.datetime "updated_at"
end

end

我的代码有问题还是 RubyMine 配置有问题?

更新:
如果我使用 Mysql2 或 sqllite3 gem,问题是一样的

最佳答案

这是一个常见的 RubyMine 错误,通常可以通过运行 File/Invalidate Caches... 来解决。

关于ruby-on-rails - RubyMine 错误 : Unable to find associated Rails Model for ':users' associations failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27341617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com