1
安裝機械化我在Ubuntu 12.04使用Ruby 1.8.7和rubygem 1.8.15一些問題,當我在紅寶石
首先,我在sudo gem install mechanize --no-ri --no-rdoc
它似乎運作良好類型。
Building native extensions. This could take a while...
Fetching: ntlm-http-0.1.1.gem (100%)
WARNING: ntlm-http-0.1.1 has an invalid nil value for @cert_chain
Fetching: webrobots-0.0.13.gem (100%)
Fetching: unf_ext-0.0.5.gem (100%)
Building native extensions. This could take a while...
Fetching: unf-0.0.5.gem (100%)
Fetching: domain_name-0.5.4.gem (100%)
Fetching: mechanize-2.5.1.gem (100%)
Successfully installed nokogiri-1.5.5
Successfully installed ntlm-http-0.1.1
Successfully installed webrobots-0.0.13
Successfully installed unf_ext-0.0.5
Successfully installed unf-0.0.5
Successfully installed domain_name-0.5.4
Successfully installed mechanize-2.5.1
7 gems installed
然後我寫了我的第一個程序
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
這是行不通的
./mechanize.rb uninitialized constant Mechanize (NameError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in gem_original_require'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from mechanize.rb:2
有人能幫助我嗎?
太棒了!它的工作原理。 – user1668903
它不需要行爲不當,但軌道加載類的方式文件名預計是類名,所以當你有mechanize.rb它期望找到它的類名機械化,因此導致未初始化的常量異常 – bjhaid
@bjhaid - 實際上問題是1.8從'.'加載mechanize.rb,而不是由於'LOAD_PATH'問題引起的gem文件夾問題。這不是鐵軌問題,這裏沒有鐵軌。 – pguardiario