Search code examples
ruby-on-railsrubyubunturubyminerubymine-7

RubyMine error: Unable to find associated Rails Model for ':users' associations failed


I'm working on some tutorial and i'm having some problems. RubyMine can't find associated Rails Model for ':users' associations failed

I'm using:
- RubyMine 7
- Ruby version meneger (rvm)
- ruby-1.9.3-p551 [ x86_64 ]
- ruby-2.1.5 [ x86_64 ]
- rails Rails 4.1.8

- Gem sqllite3

My models are:

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

Is there something wrong with my code or is this some wrong RubyMine configuration?

UPDATE:
Problem is the same if i use Mysql2 or sqllite3 gem


Solution

  • Looks like the problem is in RubyMine editor (bug)! If you run your application let's say on ruby-2.1.5 and you change you RubyMine setting (Ruby SDK and gems) to some other version and then change back to ruby-2.1.5 version, you will get this error.

    Quick fix is that you create a new project and copy paste those files there