RubyMine 5.4: "unable to find associated rails model"

Hi,
i'm using RubyMine 5.4 with Ruby 2 and Rails 4 and I'm getting this alert all time: "unable to find associated rails model"
How to fix it?

Bildschirmfoto 2013-09-16 um 14.27.45.png
Bildschirmfoto 2013-09-16 um 14.27.51.png

and so on...

4 comments

I'd like to add I'm having exactly the same problem, and it's happening in the 6.0 EAP as well.

http://i.imgur.com/gxqSEba.png
Ruby 2.0.0p247 - One thing to note here is that I'm not using all of Rails, merely ActiveRecord by itself plus whatever dependencies that pulls in.

Things I've tried:

  • Splitting the models out to individual files where they would be in a proper rails project (app/models/profile.rb and so on),
  • Different gem versions (AR 3/4 makes no difference)
  • Different RubyMine versions (happens all the way back to 3.x at least)
  • Defining the models in all other possible orders
  • Requiring db/schema.rb in this file


This is definitely an IDE issue, as the code as shown above is usable and works. Dumping out to a pry shell directly under those lines leaves all three models accessible and usable, with the associations working as they should.

0

I'm having exactly the same problem.... what's going on?.

0

I'm having exactly the same problem.... what's going on?.



Attachment(s):
Skärmavbild 2013-11-18 kl. 12.38.22.png
0

I opened a bug on this, and Jetbrains has acknowleged it as a known problem.

In the meantime, If you're doing what I did and are using Active Record in a non-rails project, the workaround to killing these bogus inspections was to convince RubyMine that it's operating inside of a Rails project anyways.

To do that:

  • Move your models into their own files under (project root)/app/models/(modelname).rb
  • Create a folder under the project root called config
  • Create two empty files under this folder called application.rb and routes.rb
  • Exit Rubymine and delete the .idea folder under project root (Careful: This will trash some of your settings.)


Upon next startup, you should see the boilerplate Rails run options in the toolbar at the top (Development: your-project-name), and more importantly the inspection error will be gone.

This may cause other issues with dependency resolution as you're essentially tricking the IDE, but I haven't found anything too out of the ordinary yet.

Your mileage may vary, void where prohibited, kids eat free, lorem ipsum, etc.

0

Please sign in to leave a comment.