无法加载'机械化'在rails 4.0.2中

时间:2014-01-31 04:11:46

标签: ruby-on-rails ruby mechanize-ruby

在rails交互式shell(rails c)中,当我运行No such file to load -- Mechanize'时收到错误消息:require 'mechanize'

奇怪的是,当我在ruby shell(require 'mechanize')上输入irb时,我没有收到任何错误。

示例输出如下所示:

    rails c 
    Loading development environment (Rails 4.0.2)
    irb(main):001:0> require 'mechanize'
    LoadError: cannot load such file -- mechanize
     from /home/********/.gem/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
     from /home/********/.gem/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
      from /home/********/.gem/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
      from /home/********/.gem/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from (irb):1
      from /home/********/.gem/ruby/2.1.0/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
      from /home/********/.gem/ruby/2.1.0/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
      from /home/********/.gem/ruby/2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:62:in `<top (required)>'
      from bin/rails:4:in `require'
      from bin/rails:4:in `<main>'

此致

1 个答案:

答案 0 :(得分:3)

将此添加到Gemfile

gem 'mechanize'

然后在shell上执行此命令

bundle