Ruby on Rails Integration

Because writing a web interface for a telephony system is so highly desired and Ruby, the language with which Adhearsion is written, just happens to have one of the best web development frameworks ever developed, Ruby on Rails integration was an obvious need.

Adhearsion's Rails integration is very easy to use. When you create a new application, take a look at the config/startup.rb file. It should look something like this:

config.enable_rails :path => 'gui', :env => :development
Uncomment the line to enable the integration. That's it!

Adhearsion and Rails will run as separate processes. All of your ActiveRecord models, including any Rails plugins you may have installed for them, are now available to use in your Adhearsion app. Nothing of your Adhearsion application will be available in your Rails application.

The two arguments you specify instruct Adhearsion where to find the folder containing your Rails app and what Rails environment to use. If you don't want your Rails application to be a subfolder of your Adhearsion application, you may create a symlink which points to the Rails folder within the Adhearsion application or you can provide an absolute path.

Merging YAML configuration as well

When using a component, you may want to merge that components YAML configuration with that of Rails, so that you have all of your configuration in one place. To do this, simply add something like this to your component's intialization:

#What to do when Adhearsion starts
initialization do
  yaml_file = File.join RAILS_ROOT, "config", "application.yml"
  if File.exist? yaml_file
   ::APP_CONFIG = YAML.load_file yaml_file
  else
    abort "#{yaml_file} does not exist!"
  end
end

Then simply start adding your configuration items to RAILS_ROOT/config/application.yml. It is recommended to name space them, something like this:

adhearsion:
     timeout: 3
     trunk: grid
Then, you may start using that configuration in your component as follows:

 ::APP_CONFIG['adhearsion]['timeout']

Asynchronous communication

Adhearsion can asynchronously communicate with Rails in one of two ways ideally:

There are other ways Adhearsion and Rails could communicate (for example, using the filesystem) but the above two ways are recommended. The database and MQ options are desirable because they will usually queue messages if the Rails or Adhearsion processes happen to die.

If you're looking for open-source message queue middleware servers, here are a few:

You'll probably want to write custom Adhearsion components using Ruby client libraries. A Stomp client library can be found here and an AMQP client can be found here. These will soon have first-class components you can use in your applications.

Synchronous communication

If you want truly synchronous communication between your Rails application and Adhearsion, it's best to create a new component and add methods to the methods_for(:rpc) scope. You can then execute those methods synchronously through any RPC component you can find. Adhearsion comes with built-in support for DRb, though you could also use the restful_rpc method that comes with Adhearsion.

Also, some of the other MQ protocols support synchronous communication, notably Stomp and AMQP. Presently there are no components which streamline this, but the Adhearsion community would be more than happy to accept them!


Browse Space

- Pages
- News
- Labels
- Attachments
- Bookmarks
- Mail
- Advanced
- Activity

Explore Confluence

- Popular Labels
- Notation Guide

Your Account

Log In

or Sign Up  

Other Features

Add Content