roseflow-rails gem and engine provides a simple and convenient way to add Roseflow interactions in a Ruby on Rails application. This documentation will guide you through the process of adding the gem and the engine to your Rails application.
- Ruby on Rails application (Rails 6.x or newer)
- Roseflow gem
Add the roseflow-rails gem to your Rails application's Gemfile:
bundle install to install the gem.
Specify Roseflow configuration in an initializer generated by the installer.
# config/initializers/roseflow.rb Roseflow.configure do |config| ... end
Define interactions in
HTTP APIs for your interactions
The engine provides you a simple way of providing access to your interactions.
roseflow-rails engine in your
# config/routes.rb Rails.application.routes.draw do mount Roseflow::Rails::Engine => "/roseflow" end
Creating an Interaction with HTTP API
To create an interaction that can be accessed via the HTTP API provided by the engine, ensure that your interaction class extends relevant modules:
# app/interaction/my_interaction.rb class MyInteraction extend Roseflow::Interaction extend Roseflow::Interaction::WithHttpApi api_resource_name "special_inference" def self.call(context) # Your interaction logic end end
The engine generates a POST route for each interaction that extends
Roseflow::Interaction::WithHttpApi. The route follows the format
The route for
MyInteraction would be
/interactions/special_inference. If you mount the engine at
/roseflow, then the full path to the endpoint would be
Providing context in the endpoint call
The engine will look for
context param hash in the request that it will supply to the interaction as the context. If no
context param is found, the interaction is called with an empty context.