MailCatcher不能与VM上的rbenv一起使用

时间:2014-08-25 12:49:58

标签: ruby virtual-machine vagrant virtualbox rbenv

我在使用rbenv管理的VM(VirtualBox)中安装了MailCatcher。 但是,mailcatcher不起作用,在下面输出错误信息:

`require': cannot load such file -- i18n/core_ext/string/interpolate (LoadError)

似乎i18n没有安装,但我安装了它。

[vagrant@localhost ~]$ gem list i18n

*** LOCAL GEMS ***

i18n (0.7.0.beta1)

我在AWS EC2中安装与此相同,它可以工作。

我的虚拟机会发生什么?

---详情---

操作系统:CentOS 6.5

Ruby:2.1.1,rbenv 0.4.0

整个错误消息:

[vagrant@localhost ~]$ mailcatcher--http-ip 192.168.33.12
/home/vagrant/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- i18n/core_ext/string/interpolate (LoadError)
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-3.2.19/lib/active_support/core_ext/string/interpolation.rb:2:in `<top (required)>'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-3.2.19/lib/active_support/core_ext/string.rb:9:in `<top (required)>'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-3.2.19/lib/active_support/core_ext.rb:2:in `block in <top (required)>'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-3.2.19/lib/active_support/core_ext.rb:1:in `each'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-3.2.19/lib/active_support/core_ext.rb:1:in `<top (required)>'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mailcatcher-0.5.12/lib/mail_catcher.rb:1:in `<top (required)>'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/vagrant/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/mailcatcher-0.5.12/bin/mailcatcher:3:in `<top (required)>'
    from /home/vagrant/.rbenv/versions/2.1.1/bin/mailcatcher:23:in `load'
    from /home/vagrant/.rbenv/versions/2.1.1/bin/mailcatcher:23:in `<main>'

4 个答案:

答案 0 :(得分:2)

rails 4.2 beta / activesupport-4.2.0.beta2取决于i18n(&lt; 0.8,&gt; = 0.7.0.beta1)。

如果加载了i18n的beta gem,

mailcatcher(0.5.12)会抛出你的错误。

如果您未使用rails 4.2 beta,则可以卸载测试版

gem uninstall i18n -v i18n-0.7.0.beta1

这是在gem

的多个问题中引用的

https://github.com/sj26/mailcatcher/issues/164

https://github.com/sj26/mailcatcher/issues/155

答案 1 :(得分:2)

使用已发布的答案的组合,这是我提出的解决方案:

我的环境:

  • rbenv
  • rails 4.1.8
  • i18n(0.7.0.beta1)

我的问题: 在我现有的rails项目文件夹中运行gem install mailcatcher后,我运行了mailcatcher并得到了:

  

`require':无法加载此类文件 - i18n / core_ext / string / interpolate(LoadError)

我不想在我现有项目的文件夹中更新i18n gem,因为我项目中的所有内容都运行良好。

根据@ joostvanrijn的建议,我决定专门为MailCatcher创建一个单独的rails项目文件夹。我将文件夹命名为mailcatcher。 在我新创建的/mailcatcher文件夹中,我运行了gem install mailcatcher。然后我跑了gem update i18n,这让我i18n-0.7.0。 最后,我打电话给mailcatcher,它顺利运行。

后来,我遇到了MailCatcher的另一个问题:

虽然我可以访问http://127.0.0.1:1080,但发送电子邮件会失败

  

已完成500内部服务器错误

     

Net :: ReadTimeout(Net :: ReadTimeout)

我试图通过转到http://127.0.0.1:1080然后点击“退出”来退出MailCatcher,但这只会带我到http://mailcatcher.me并且实际上不会杀死该进程。

要终止此过程,我使用lsof -i -n -P | grep TCP查找在127.0.0.1:1025127.0.0.1:1080上运行的进程并使用kill -9 PID

我从Discourse post了解到Net::ReadTimeout是由于MailCatcher中的错误导致的,解决方法是使用mailcatcher -f在前台运行MailCatcher。这解决了我的问题,现在我可以毫无问题地“抓住”电子邮件。耶!

答案 2 :(得分:1)

对于任何遇到rbenv问题的人:我找到了解决方法。确保使用没有安装rails 4.2 beta gem的ruby版本。 (我有一个较旧的项目,我可以在那里进行安装和运行mailcatcher没有问题。

你不一定要创建一个新文件夹(名为&#34; mailcatcher&#34;例如)创建一个支持版本的.ruby-version,这样你就可以从那里运行mailcatcher

答案 3 :(得分:0)

我也使用rails 4.2并解决了我为mailcatcher安装另一个ruby版本的问题。

我正在使用RVM和ruby 2.1.5 for rails,所以,我刚安装并使用2.1.4 for mailcatcher:

rvm install 2.1.4 --with-readline-dir=/usr/include/readline
rvm 2.1.4
gem install mailcatcher
mailcatcher

使用rbenv你可以这样做:

CONFIGURE_OPTS="--with-readline-dir=/usr/include/readline" rbenv install 2.1.4
rbenv shell 2.1.4
gem install mailcatcher
mailcatcher

这不是一个完美的解决方案,但在mailcatcher修复此问题之前,这是一个很好的解决方法。