User:Zverik/Rails Port on Windows
Tools
The installation process is very long and entertaining. Consider it a fun quest.
PostgreSQL
This DBMS is essential for most of OSM tools, so you'd better have it installed. Download page, from there "One click installer" and choose 8.3 version (but 8.4 should be also ok). Don't forget to install PostGIS extension: it will be useful when you're trying mapnik. After installation, run pgAdmin and open your local server.
Add login role with name "openstreetmap" (without quotes, obviously) and three databases with owner openstreetmap, utf-8 encoding and names "openstreetmap", "osm_test" and "osm" (yup, like that). After that open command line, navigate to %PROGRAM_FILES%\PostgreSQL 8.x\bin and execute the following line:
psql -U postgres -d openstreetmap < ../share/contrib/btree_gist.sql
I doubt you'll need a production database ("openstreetmap") though.
Ruby on Rails
Get version 1.8 (not 1.9!) in .exe from this page. Enable "add ruby executables to your PATH". Gems are included in the installer. After that, type all following commands:
gem install -v=2.3.14 rails gem install timecop gem install pg gem install ruby-openid gem install rack-openid gem install oauth gem install libxml-ruby
libxml is installed, but dlls will not be found. Copy libxml2-2.dll and libiconv2.dll from <ruby-path>\lib\gems\1.8.x\gems\libxml-ruby-xxx\lib\libs to your <ruby-path>\bin directory.
if you want to make .bat, do notice that gem is a batch file, and you should prepend every line with call.
Bad Dependencies
Gems rmagick and SystemTimer will fail to install, because they need to be compiled. You need something called DevKit, get it from here, but don't leave that site: click "Help" and then "Development Kit" in the middle of the page. Instruction for installation are there. In short, unpack sfx-archive into your rails folder, run ruby dk.rb init and ruby dk.rb install.
Install ImageMagick from here (at the bottom there are windows binaries), choose Q8-windows-dll. Install it into Ruby folder with no spaces in the name, e.g. C:\Ruby\ImageMagick. Enable 'headers' checkbox in the process. Then, as StackOverflow suggests, run the following .bat-file (but correct paths for your installation):
set CPATH=C:\Ruby192\ImageMagick\include set LIBRARY_PATH=C:\Ruby192\ImageMagick\lib gem install rmagick
...and it should be ok. If not, check paths again.
SystemTimer fails to build no matter what. Some solutions include installing Cygwin, but that's too much. Thanks to Ghazel (?), this should work:
gem install ghazel-SystemTimer
Git and sources
Install git. I used googlecode one. Check "run git from windows command prompt", it would make everything easier.
Then enter Ruby folder and type
git clone git://git.openstreetmap.org/rails.git
and wait: 90 MB of sources (in "rails" folder) are in order.
What different folders mean, see here.
Go to rails\config and copy postgres.example.database.yml to database.yml in the same folder and change login/password to those you've added to database (user=openstreetmap if you followed this instruction). Also, database names can be adjusted therem so you don't have to follow that strange naming, and add a prefix, for example.
Then, copy example.application.yml to application.yml. The rails_port settings are stored in this file.
Since we replaced SystemTimer gem with another, edit environment.rb and add ghazel- before SystemTimer.
What is Rake
Now run
rake gems:install rake db:migrate rake test
The last command tests the installation. If everything is ok, good! Now let's import us some data.
Current problem
C:/Ruby192/rails/app/models/spam_observer.rb:6: syntax error, unexpected ':', expecting keyword_then or ',' or ';' or '\n' when record.is_a?(User): user = record ^ C:/Ruby192/rails/app/models/spam_observer.rb:7: syntax error, unexpected keyword_when, expecting keyword_end when record.is_a?(DiaryEntry): user = record.user ^ C:/Ruby192/rails/app/models/spam_observer.rb:7: syntax error, unexpected ':', expecting keyword_end when record.is_a?(DiaryEntry): user = record.user ^ C:/Ruby192/rails/app/models/spam_observer.rb:8: syntax error, unexpected keyword_when, expecting keyword_end when record.is_a?(DiaryComment): user = record.user ^ C:/Ruby192/rails/app/models/spam_observer.rb:8: syntax error, unexpected ':', expecting keyword_end when record.is_a?(DiaryComment): user = record.user ^ C:/Ruby192/rails/app/models/spam_observer.rb:15: syntax error, unexpected keyword_end, expecting $end
Also, no rails_port component on trac. http://trac.openstreetmap.org/ticket/3981
Populating the database
For that you'll need Osmosis. For osmosis, you'll need Java (if you don't have it already, since... JOSM!) It's stupid to import the whole planet, so take the extract of a region you like (your country, for example). I prefer PBF.
osmosis --read-pbf file=<country>.pbf --write-apidb-0.6 populateCurrentTables=yes host="localhost" database="openstreetmap" user="openstreetmap" password="<password>" validateSchemaVersion=no
There is a strange recommendation in The Rails Port#Populating the database to reset auto-increment sequences.
Ok Go!
From the rails port folder, run
ruby script/server
And check http://localhost:3000/.