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

标签 ruby-on-rails ruby ubuntu rubymine rubymine-7

我正在编写一些教程,但遇到了一些问题。 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/

相关文章:

jquery - 使用 Turbolink 时如何清除窗口变量

ruby-on-rails - 即使验证失败,Rails 也会强制对象保存

ruby-on-rails - 如何在 spree commerce 中创建主题

mysql - 运行 Ruby 脚本时在 Mac 上正确编码,但在 Ubuntu VPS 上不正确

ruby - 在 Ruby 中测试标准输入

php - PMA 4.5.2.0 file_exists() : open_basedir restriction in effect

ubuntu - 无法从 S3 下载文件

ruby-on-rails - 如何在 Ruby on Rails 中基于每个操作禁用日志记录?

ruby - 算法删除元音,意外结果

python 程序不工作 apt-get install xvfb