New York Public Library Map Warper 提供地圖校正的線上服務,它將館藏的地圖,開放給使用者進行對應校正,成果就能搭配 Open Street Map 來顯示。
程式碼主體是 Ruby on Rails,在 Ubuntu 12.04 環境下,啟動前要安裝 cgi-mapserver,順利的話,連帶把 libgdal 裝好,想用 MySQL 的話,就執行 sudo apt-get install mysql-server mysql-common mysql-client libmysqlclient-dev。還有 curl 和 git,以及 libmagickcore-dev libmagickwand-dev。
身為 Rails 菜鳥,最簡單的安裝方式,當然還是 apt-get install ruby-rails,但這樣裝的版本會很舊,提示建議要先裝 nodejs (套件名稱不是 node 要小心) 和 RVM (Ruby Version Manager),在安裝 RVM 前,先確認 Ubuntu 已裝好下列套件:
$ sudo apt-get install build-essential libssl-dev libpcre3-dev libncurses5-dev libreadline6-dev。
執行 curl -L https://get.rvm.io | bash -s head --autolibs=3 --ruby 後,留意裝的 ruby 版本號碼,例如 2.0.0-p0 之類,如果不是自己想要的版本,就要再想法子更新。
按照訊息提示,執行 source /home/marr/.rvm/scripts/rvm 就可以使用了,終於可以 gem install rails 啦。
執行了 nypl-warper/script/server 後,出現訊息:
Missing the Rails 2.3.5 gem. Please `gem install -v=2.3.5 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.
此處的 `gem install -v=2.3.5 rails` 對我而言,像是繞路的陷阱,執行到 Fetching: rails-2.3.5.gem 時,遇到:
rails's executable "rails" conflicts with railties Overwrite the executable? [yN]
選 N 的話,會結束安裝:
ERROR: Error installing rails: "rails" from rails conflicts with installed executable from railties
後來又遇到:
/home/marr/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/ rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- iconv (LoadError)
為了把干擾降到最低,決定把 Ubuntu 原本裝的 ruby 相關套件都 apt-get purge 移除,刪掉 $HOME/.rvm 重裝 ruby 1.9.3 rails 2.3.5。
Rails 2.3.5 application starting on http://0.0.0.0:3000 /home/marr/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247: in `to_specs': Could not find oauth (>= 0.3.5) amongst [actionmailer-2.3.5, actionpack-2.3.5, activerecord-2.3.5, activeresource-2.3.5, activesupport-2.3.5, bundler-1.3.4, rack-1.0.1, rails-2.3.5, rake-10.0.4, rubygems-bundler-1.1.1, rvm-1.11.3.6] (Gem::LoadError)
再 gem install oauth
Fetching: oauth-0.4.7.gem (100%) Successfully installed oauth-0.4.7 1 gem installed Installing ri documentation for oauth-0.4.7... Installing RDoc documentation for oauth-0.4.7...
遇到 in `require': cannot load such file -- geo_ruby (LoadError) 使用 gem install geo_ruby 說「沒有 geo_ruby」,改用 gem install georuby 成功,遇到 in `require': cannot load such file -- pg (LoadError) 使用 apt-get install postgresql postgresql-contrib libpq-dev 和 gem install pg 成功。
接著是 invalid multibyte char (US-ASCII) (SyntaxError) 錯誤,在檔案前面加:
#!/bin/env ruby # encoding: utf-8
至此,總算 ./server 跑起來了,新的訊息是:
The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql. Status: 500 Internal Server Error cannot load such file -- mysql
補了 sudo apt-get install libmysqlclient-dev 再 gem install mysql 應該是搞定了。
修改 config/database.yml 後,執行 rake db:migrate 遇到:
ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' instead.
先修改 Rakefile 把 rake/rdoctask 換成 rdoc/task。
再補 sudo apt-get install libgdal1-dev 雖然可以處理 gdal-config 找不到的問題,但 gem install gdal 還是出現 libgdal not found 問題。
遇到 Can not load gdal/gdal 改成 gdal 可過關。
找時間繼續...