The Rails Port
From OpenStreetMap
The Rails port is the current version of OSM's server code - API, web front end and everything. If you have a Unix-like system (Linux, Mac OS X or a BSD) then you can install it on your own machine, so that you can make and test improvements to the code locally, then commit them to the OSM server. (This is not currently trivial for Windows users.)
Contents |
Ruby on Rails
Ruby on Rails is a web development framework, written in Ruby. It is intended to make developing database driven web-based applications faster and more productive. For developers, this means less messing around configuring and more coding.
You should have some familiarity with Ruby and Model-View-Controller architectures before you start hacking on the OSM Rails port. Here are some resources that might help you:
- http://www.ruby-lang.org/ - The homepage of Ruby which has more links and some great tutorials.
- http://www.rubyonrails.org/ - The homepage of Rails, also has links and tutorials
Installing Rails
Prerequisites/Dependencies
- Ruby 1.8.4 or higher.
- Ruby libxml bindings version 0.8.1 or higher.
- composite key plugin version 0.9.93.
- Rails 2.0.2
- MySQL 4.1.0 or higher
Platform-specific instructions
Gems (libraries)
Other gem installations you need (these may be covered by the platform-specific instructions above):
- Make sure ImageMagick is on your server, it is required by RMagick.
- Execute as root (sudo on Ubuntu) and answer yes to all questions
# gem install -v=2.0.2 rails # gem install mysql # gem install libxml-ruby # gem install -v=0.9.93 composite_primary_keys # gem install RMagick
Getting the OpenStreetMap code
Download the OSM source tree using subversion (see Getting The Source).
cd <path-to-osm-source>/sites/rails_port
If you hit the externals issues (http://svn.kylemaxwell.com/ is always down), then call
svn co --ignore-externals http://svn.openstreetmap.org/
and
svn update <path-to-osm-source>/sites/rails_port/vendor/plugins
to get some needed externals.
If getting the externals fails; here are some alternative ways to get them:
file_column external
#cd <path-to-osm-source>/sites/rails_port/vendor/plugins #svn co http://opensvn.csie.org/rails_file_column/plugins/file_column/trunk file_column
sql_session_store external
#cd <path-to-osm-source>/sites/rails_port/vendor/plugins #svn co svn://svn.usablelabs.com/kv/trunk/vendor/plugins/sql_session_store/ sql_session_store
Or download an archive of the files from http://dev.openstreetmap.org/~tomh/vendor.zip .
At this point, you should read the READMEs, which are located:
<path-to-osm-source>/sites/rails_port/README <path-to-osm-source>/sites/rails_port/db/README
Rails uses a preconfigured directory structure. Notable directories are:
db/ - Contains migrations and SQL to create databases (not the actual database) config/ - Application configuration files app/ - The application source code: app/controllers - The Controllers app/models - The Models app/views - The Views
Setting up an OSM database
If you want to do any substantial work on OSM, you'll need a test database full of OSM data to develop against.
Creating a new database
You may create it with your preferred client or run this command on Unix systems:
$ mysql -u <uid> -p
(where <uid> is the username of an administrative user, e.g. root )
create database openstreetmap default character set utf8; grant all privileges on openstreetmap.* to 'openstreetmap'@'localhost' identified by 'openstreetmap'; flush privileges; exit
Installing the quadtile functions
This section is not essential and can be skipped by most users.
You can speed up the database loading by installing a specially-written MySQL function, providing quadtile support, before the database will run on your system. (This isn't essential.) The instructions in db/README for this explain how to do it. In brief:
cd db/functions make
- Make sure the db/functions directory is on the MySQL server's library path and restart the MySQL server.
- On Linux the easiest way to do this is to create /etc/ld.so.conf.d/osm.conf, and place the path to the db/functions directory in it and then run the ldconfig command as root.
- On OS X: sudo ln -s /path_to_your_osm_install/sites/rails_port/db/functions/libmyosm.so /usr/local/lib/libmyosm.so
- Log into MySQL (mysql -u <uid> -p openstreetmap, where <uid> is root or another administrative user)
create function tile_for_point returns integer soname 'libmyosm.so'; create function maptile_for_point returns integer soname 'libmyosm.so';
- exit
Creating the database structure
First make sure your config/database.yml file has the correct connection settings for the database. Under the development section you should have something like:
development: adapter: mysql database: openstreetmap username: root password: (mysql root password if you set one) host: localhost socket: /var/run/mysqld/mysqld.sock (or wherever your equiv mysql.sock file is located)
socket is not necessary on all systems (e.g. OS X). Users on some systems might see an error like "/tmp/mysql.sock not found" if the link to the socket file is not found. The location on Debian/Ubuntu systems is that shown above: on other systems you might find it at /var/lib/mysql/mysql.sock. Making a symbolic link to the real mysql.sock file is a possible alternative. For example, on FedoraCore5 the following is sometimes needed:ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
Then, to create the database structure, navigate to the <path-to-osm-source>/sites/rails_port directory, and execute this as root:
# rake db:migrate
Populating the database
Information on populating the database can be found on the Planet.osm page.
Firing up Rails
The database is now configured and you are ready to roll with rails. On Unix-like systems as root do:
cd <path-to-osm-source>/sites/rails_port ruby script/server
In your favourite web-browser, go to:
localhost:3000
You should see the OSM rails port.
Troubleshooting
Rails has its own log. To inspect the log, do this:
tail -f <path-to-osm-source>/sites/rails_port/log/development.log
If you have more problems, please ask on the dev mailing list (dev@openstreetmap.org) or on IRC. Here are some frequently encountered issues.
When running rake db:migrate
- Running causes the error "undefined method 'file_column' for #<Class:0x########>."
- Ensure file_column has been pulled into vendor/plugins, if it svn externals are still broken, cd there and run:
svn co http://opensvn.csie.org/rails_file_column/plugins/file_column/trunk file_column
When booting Rails
- If you get an error message about SQLSessionStore, the external dependencies (in /sites/rails_port/vendor/plugins) haven't been installed. Update your Subversion working copy and check that everything from other sites is being pulled in.
- If you get an error message about "undefined method 'gem' for main::Object", see here.
- If you get an error message about uninitialized constant RLIMIT_AS, comment out line 2 of sites/rails_port/config/initializers/limits.rb .
- If you get errors about rspec (no such file to load -- spec/rake/spectask), then install rspec: ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec - see http://rspec.rubyforge.org/documentation/rails/install.html
When using the site
- When you open localhost:3000, if you get a message like 'host myispname.co.uk is not allowed to connect to this database', that suggests you are trying to contact to the real live OSM database, rather than your own one. Edit sites/rails_port/config/database.yml, and change the IP addresses ('128....') to 'localhost'.
- If the OSM page appears unstyled and incomplete, look at your browser/access logs - they may show requests for files like "localhost:3000/foo/bar/87623459". You can fix this by editing sites/rails/port/config/environments/development.rb and adding the line
ENV['RAILS_ASSET_ID'] = ''
or by removing config/initializers/asset_tag_helper.rb from your local install.
- If you want to create a new user, but haven't got an SMTP server set up to send out the confirmation mail, simply create the user, then edit the 'users' table and set active=1 in the relevant row.
Maintaining your installation
If your installation stops working for some reason:
- The OSM database schema is changed periodically and you need to keep up with these improvements. Go to your rails_port directory and
rake db:migrate
- Make sure your libraries are up-to-date (gem update rails, etc.)
Getting GPX importing to work
You don't need the GPX import facility to work before using the rest of the Rails port. However, if you want to hack on this bit, too:
- Make sure you have set the database settings for 'production' (config/database.yml) as well as 'development'
- Make sure you have set your SMTP server in config/environment.rb (circa line 60)
- Install the 'daemons' package: gem install daemons
- Create directories at /home/osm/gpx and /home/osm/icons
- Then start the import daemon running: script/daemons start
If you run into trouble, you can turn on logging by adding this line to lib/daemons/gpx_import_ctl
options[:log_output] = true
Logs will then be written in the log dir.
Miscellanea
It is possible to produce diagrams of the rails port using railroad. More information is in The Rails Port/Railroad diagrams.
Some information about The Rails Port/Testing testing.

