Setting up a Rails App to use ActiveFedora¶
Overview¶
This document explains how to
- Install the active-fedora gems
- Create a rails app
- Set up rspec (optional)
- Freeze the gems into your app (optional)
- Set environment variables so your app can find Fedora and Solr
- Create some methods in your application controller for loading connections to Fedora & Solr
Once you've set up the Rails app, you will be ready to start Creating ActiveFedora Models
Setup Steps¶
Create the rails app
rails my-app-name cd my-app-name
Install the gems if you haven't already
sudo gem install active-fedora
Freeze the gems into your app (optional)
sudo rake gems:freeze GEM=ruby-fedora VERSION=1.0.4 sudo rake gems:freeze GEM=active-fedora VERSION=1.0.4
Create config/initializers/fedora_repository.rb and put this into it:
require "active_fedora" FEDORA_URL = 'http://fedoraAdmin:fedoraAdmin@127.0.0.1:8080/fedora' SOLR_URL = 'http://127.0.0.1:8080/solr/'
- see sample fedora_repository.rb
- if you have set Fedora to require SSL for API-M operations, set FEDORA_URL to FEDORA_URL = 'https://fedoraAdmin:fedoraAdmin@127.0.0.1:8443/fedora'
Edit app/controllers/application.rb addign these methods:
private
def require_fedora
Fedora::Repository.register(FEDORA_URL, session[:user])
return true
end
def require_solr
ActiveFedora::SolrService.register(SOLR_URL)
end
- see sample application.rb
Optionally set up basic shared authentication
Edit config/environment.rb adding these lines:config.gem "ruby-fedora", :version => '>= 1.0.4' config.gem "active-fedora", :version => '>= 1.0.4' config.gem "haml"
Set up RSpec (optional)¶
If you plan to use rspec, do the following
Run the rspec scriptscript/generate rspec
Set FEDORA_TEST_URL and SOLR_TEST_URL in spec/spec_helper.rb
FEDORA_TEST_URL = 'http://fedoraAdmin:fedoraAdmin@127.0.0.1:8080/fedora' SOLR_TEST_URL = 'http://127.0.0.1:8080/solr/'
Notes¶
Important: If you are not using any activerecord objects at all, you will have to either turn off rails' sql obsession, or set up sqlite3 databases and run db:migrate to give them empty schemas
Make sure to register Fedora::Repository and ActiveFedora::SolrService if/when you need them in tests.
Make sure to call require_solr and/or require_fedora in your controllers whenever a method needs to connect to them. This is usually handled by the :require_fedora and :require_fedora controller methods.
What You've Just Done¶
You now have a Rails app that's ready to use with ActiveFedora.
See Creating ActiveFedora Models to get started using ActiveFedora in your app.