Browse Code | Bugs & Patches | Downloads | Introduction | Sample App
Since the article introducing Concierge rambled somewhat, here's a sample Concierge Rails app.
Installation
$ sudo gem install concierge
Make sure you have Rails 1.2.3 and Sqlite3 installed.
Running The Greeter
You might like to run the sample app first as proof this stuff works:
$ cd ~/Projects
$ wget http://rubyforge.org/frs/download.php/21986/greeter.tgz
$ tar xzvf greeter.tgz
$ cd greeter
$ script/server
$ open http://localhost:3000/greetings
Enjoy your greeting.
The Code
Yes, it's the hello world service. The relevant bits follow.
config/environment.rb
require 'concierge'
CodeRhythm::Concierge::Loader.configure do |config|
config.service_config_path = "#{RAILS_ROOT}/config/services"
config.env = RAILS_ENV
end
Dependencies.load_paths.unshift "#{RAILS_ROOT}/lib/services"
On edge rails config/initializers/concierge.rb is probably a better choice.
config/services/greeter.yml
development:
greeting: hello
test:
greeting: hola
production:
greeting: buenos dias
app/controllers/application.rb
class ApplicationController < ActionController::Base
include CodeRhythm::Concierge::Consumer
end
app/controllers/greetings_controller.rb
class GreetingsController < ApplicationController
consumes_service :greeter
def index
render :text => greeter.greet
end
end
lib/services/greeter.rb
class Greeter < CodeRhythm::Concierge::Provider
provides_service :greeter
def greet
config.greeting
end
end
This will help a lot. Perhaps it’s time to write a generator that will do the grunt work of getting Concierge installed into a Rails app. Or maybe it should be a plugin? Anyway, then you can have a tutorial like: