AllegroGraph on Rails: Preliminary Tutorial

This project is still not ready for production use. But if you'd like to check it out of Subversion and take a look, here's how.

We eventually hope to simplify many of these steps.

1. Install AllegroGraph

Download the AllegroGraph Free Server Edition, and install it normally.

Find the entry for "Start AllegroGraph Server Edition" in your start menu, right click on it, and select "Properties".

Add the arguments -http 8111 to the command line, click "OK", and start the server.

2. Install ActiveRDF and Ruby on Rails

Install Ruby and Ruby on Rails in the usual fashion. On some platforms, you may also need to install RubyGems.

Next, install ActiveRDF and some support libraries:

gem install activerdf activerdf_sparql builder uuidtools

Depending on your operating system, you may need to use sudo gem install.

The AllegroGraph adapter is pre-release software, but you can get it from Subversion:

svn co agraph

cd agraph

rake package

gem install pkg/activerdf_agraph-*.gem

3. Create a repository

You can create a new RDF repository using the AllegroGraph server interface:

$ irb

> server ='http://localhost:8111/sesame')

> repo = server.new_repository("example")

To use the new repository with ActiveRDF, we also need to define any classes we plan to use. In this example, we create a class to represent a guestbook entry:

> repo.define_class('')

(This particular interface will be mostly likely be replaced by something better in the future.)

4. Build a guestbook application

Create a new Rails application:

rails guestbook

cd guestbook

Since we'll be using ActiveRDF in place of ActiveRecord, we also need to edit the config/environment.rb file. We begin by disabling ActiveRecord (look for the config.frameworks line near the top of the file):

config.frameworks -= [ :active_record ]

Then, down at the bottom of the file, add some code to set up ActiveRDF:

require 'activerdf_agraph'

$repository_uri = 'http://localhost:8111/sesame/repositories/example'

$guestbook_uri = ''

ConnectionPool.add_data_source(:type => :agraph, :url => $repository_uri)

Namespace.register :guest, $guestbook_uri


Create a file app/controllers/guest_book_controller.rb:

class GuestBookController < ApplicationController

  def index

    @new_entry =

    @entries = GUEST::Entry.find_all


  def sign

    @entry =

    @entry.guest::user_name = @params['new_entry']['user_name']

    @entry.guest::comments = @params['new_entry']['comments']

    redirect_to home_url



  def unique_uri




And add a file app/views/guest_book/index.rhtml:



    <title>Guest Book</title>



    <h1>Guest Book</h1>

    <% form_for :new_entry, @new_entry, :url => { :action => 'sign' } do |f| %>

      Name: <%= f.text_field :user_name %><br />

      Comments:<br />

      <%= f.text_area :comments, :rows => 5 %><br />

      <input type="submit" value="Sign">

    <% end %>


    <% for entry in @entries %>

      <p><b><%=h entry.user_name %></b>: <%=h entry.comments %></p>

    <% end %>



Copyright © 2017 Franz Inc., All Rights Reserved | Privacy Statement
Delicious Google Buzz Twitter Google+