4 Replies Last post: Nov 24, 2013 10:20 PM by Michael Parks  
Peter Göbel Newbie 1 posts since
Sep 16, 2013
Currently Being Moderated

Sep 16, 2013 4:30 PM

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...

Michael Parks Newbie 2 posts since
Nov 13, 2013
Currently Being Moderated
Nov 13, 2013 8:14 AM in response to: Peter Göbel
Re: RubyMine 5.4: "unable to find associated rails model"

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.

yoni pacheko Newbie 20 posts since
Jul 15, 2013
Currently Being Moderated
Nov 18, 2013 3:36 PM in response to: Peter Göbel
Re: RubyMine 5.4: "unable to find associated rails model"

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

yoni pacheko Newbie 20 posts since
Jul 15, 2013
Currently Being Moderated
Nov 18, 2013 3:38 PM in response to: Peter Göbel
Re: RubyMine 5.4: "unable to find associated rails model"

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

Michael Parks Newbie 2 posts since
Nov 13, 2013
Currently Being Moderated
Nov 24, 2013 10:20 PM in response to: Peter Göbel
Re: RubyMine 5.4: "unable to find associated rails model"

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.

More Like This

  • Retrieving data ...