我不知道这个问题到底是什么。我在rails控制台中尝试这个:
>> agent = Mechanize.new
NoMethodError: undefined method `user' for nil:NilClass
我添加了gem'mechanize'并进行了捆绑安装。我确实需要'机械化'。我也试过要求'nokogiri',每次我得到同样的错误。我尝试了4种或5种不同的方法来实例化一个新的机械化对象,但却找不到它。
我在整个rails应用程序中搜索字符串'.user',但找不到任何内容。不知道这笔交易是什么。有什么想法吗?
由于
修改
完整堆栈跟踪
NoMethodError: undefined method `user' for nil:NilClass
from /home/me/.rvm/gems/ruby-1.9.3-p448@my_app/gems/net-http-persistent-2.9.2/lib/net/http/persistent.rb:866:in `proxy='
from /home/me/.rvm/gems/ruby-1.9.3-p448@my_app/gems/mechanize-2.7.2/lib/mechanize/http/agent.rb:1189:in `set_proxy'
from /home/me/.rvm/gems/ruby-1.9.3-p448@my_app/gems/mechanize-2.7.2/lib/mechanize.rb:204:in `initialize'
from (irb):5:in `new'
from (irb):5
from /home/me/.rvm/gems/ruby-1.9.3-p448@global/gems/railties-3.2.15/lib/rails/commands/console.rb:47:in `start'
from /home/me/.rvm/gems/ruby-1.9.3-p448@global/gems/railties-3.2.15/lib/rails/commands/console.rb:8:in `start'
from /home/me/.rvm/gems/ruby-1.9.3-p448@global/gems/railties-3.2.15/lib/rails/commands.rb:41:in `<top (required)>'
from /home/me/Dropbox/Work/RubymineProjects/apps/my_app/script/rails:6:in `require'
from /home/me/Dropbox/Work/RubymineProjects/apps/my_app/script/rails:6:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
答案 0 :(得分:1)
你没有做错任何事情:几天前出现的机械化版本是错误的。我解决了这个错误只是更新了gem(即使用bundle update mechanize
)。