RubyMine not recognising gems installed with bundler in the editor

ぃ、小莉子 提交于 2019-12-23 13:06:26

问题


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


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


I had a similar issue. Rbenv was making use of an older version of ruby vs what RubyMine was using.

I had to set the local version using Rbenv and then use the same version in RubyMine. This means that running bundle install in a terminal window will install the gems into the correct "gem set"

To set the Rbenv version:

rbenv local 2.5.1



来源:https://stackoverflow.com/questions/22054219/rubymine-not-recognising-gems-installed-with-bundler-in-the-editor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!