本文介绍了RubyMine 在编辑器中无法识别使用 bundler 安装的 gem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难让 RubyMine 正确查看我的宝石.我看到的问题是编辑器屏幕无法识别任何 gem 的任何类,例如 MyClass <ActiveRecord::Base,我看到黄色警告:Cannot find 'ActiveRecord'.

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

我正在使用 bundler,我为每个项目配置了我的 gems 并安装在/some/project_dir/.bundle/gems

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

我见过这个错误:http://youtrack.jetbrains.com/issue/RUBY-14542,所以我试图通过如下启动 RubyMine 来解决这个问题:

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" 我的

我的 RubyGems 环境看起来正确 - 这是相关的摘录:

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

我看到 Ruby SDK 和 Gems 首选项面板下列出了 gem,但编辑器面板无法识别其中的任何文件.

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.

更新:我从 rails 2.3 升级到 rails 3.0(通过升级 Gemfile 并运行 bundle install),我现在可以在编辑器中看到 rails 源代码,但没有看到其他 gems.Rails 是通过 :github=> 指令安装的:

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.

交叉发布到此错误:http://youtrack.jetbrains.com/issue/RUBY-14542

推荐答案

我遇到了类似的问题,解决方法是删除 ruby​​ SDK(在首选项 ->Ruby SDK 和 Gems 中),然后将其添加回来.这将语言级别"从 2.1 提升到 2.2,并允许 Rubymine 在 ruby​​ 2.2.0/gems 中找到捆绑的 gem.我不知道 Rubymine 如何将我的 ruby​​-2.2.1-p85 的语言级别设置为 2.1,但这是一个难以追踪的微妙问题,所以我想我会分享以防其他人遇到它.我是通过使用非常有用的工具->显示 Gem 环境才发现的,这可能有助于解决类似问题.

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.

这篇关于RubyMine 在编辑器中无法识别使用 bundler 安装的 gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 08:21