Skip to content

Subscribing responders

Kris Leech edited this page Jun 5, 2014 · 1 revision
class MyController < ApplicationController
  def create
    my_service = MyService.new
    my_service.subscribe(CreateResponder.new(self), prefix: 'on')
    my_service.run
  end

  class CreateResponder
    def initialize(controller)
      @controller = controller
    end
   
    def on_success
      controller.redirect_to ..
    end

    def on_failure
      controller.render ...
    end

    private

    attr_reader :controller
  end
end