Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RubyMine not recognising gems installed with bundler in the editor

Tags:

rubymine

I'm having difficulties getting RubyMine to see my gems properly. The problem I'm seeing is that the editor screen does not recognise any classes for any gems eg for MyClass < ActiveRecord::Base, I see a yellow warning: Cannot find 'ActiveRecord'.

I'm using bundler and I have my gems configured per project and installed in /some/project_dir/.bundle/gems

I've seen this bug: http://youtrack.jetbrains.com/issue/RUBY-14542, so I'm attempting to work round this by launching RubyMine as follows:

GEM_HOME="/some/project_dir/.bundle/gems/ruby/1.8" mine

My RubyGems environment looks correct - here is the relevant extract:

....
Sdk Gem paths: 
    ~/.rbenv/versions/ree-1.8.7-2012.02/lib/ruby/gems/1.8/gems
    /some/project_dir/.bundle/gems/ruby/1.8/gems
    ~/.rbenv/versions/ree-1.8.7-2012.02/lib/ruby/gems/1.8/bundler/gems
    /some/project_dir/.bundle/gems/ruby/1.8/bundler/gems
Gems used for 'project':
    rails (bundled)
        /some/project_dir/.bundle/gems/ruby/1.8/bundler/gems/rails-857c6ee62c05
    rspec (bundled(1.3.2))
        /some/project_dir/.bundle/gems/ruby/1.8/gems/rspec-1.3.2

....

So it appears that it is using the correct path for the gems:

/some/project_dir:ls -1 /some/project_dir/.bundle/gems/ruby/1.8/gems    
    Ascii85-1.0.1
    Ascii85-1.0.2
    GeoRuby-1.3.3
    abstract-1.0.0
    ....

I see the gems listed under the Ruby SDK and Gems preferences pane, but the editor pane doesn't recognise any files from within them.

This seems like a similar issue, but I still see problems even using the workaround specified.


Update: I upgraded from rails 2.3 to rails 3.0 (by upgrading the Gemfile and running bundle install), I am now able to see the rails source in the editor, but none of the other gems. Rails is installed with the :github=> directive:

gem 'rails', :github => 'rails/rails', :branch => '3-0-stable'

So I'm thinking this might be something to do with it.

Cross posted to this bug: http://youtrack.jetbrains.com/issue/RUBY-14542

like image 483
robd Avatar asked Feb 26 '14 21:02

robd


3 Answers

I had a similar problem and the fix turned out to be removing the ruby SDK (in preferences->Ruby SDK and Gems) and then adding it back. That bumped the "Language level" from 2.1 to 2.2 and allowed Rubymine to find bundled gems in ruby 2.2.0/gems. I don't know how Rubymine managed to set language level for my ruby-2.2.1-p85 to 2.1, but this was a subtle problem that is hard to track down, so I thought I'd share in case anyone else experiences it. I only discovered it by using the extremely helpful Tools->Show Gem Environment, which may help troubleshoot similar issues.

like image 188
Ed Posnak Avatar answered Jan 01 '23 12:01

Ed Posnak


Maybe you should just set the correct Ruby in RubyMine settings menu.

Go to "File" -> "Settings" -> "Ruby SDK and Gems" (in the list at left side) and select the correct version of the Ruby.

like image 39
Riki_tiki_tavi Avatar answered Jan 01 '23 13:01

Riki_tiki_tavi


On RubyMine for Mac, still had the same issue with not finding gems. Instead of default settings from File, you need to change: RubyMine => Preferences => Languages and Frameworks => RubySDK and Gems

Then select the correct version.

like image 41
Flippakitten Avatar answered Jan 01 '23 13:01

Flippakitten