Hanami 1.3 > Hanami 2.2 : tips & notes about my journey

There is a reason why this API moved, which may help you to remember in the future: Actions in Hanami 2 are immutable, so anything that involved mutation in 1.x moved out of Action.

Defining responses used to be a mutation of the Action context:

# apps/web/controllers/dashboard/index.rb
module Web
  module Controllers
    module Dashboard
      class Index
        include Web::Action

        def call(params)
          self.status = 201
          self.body   = 'Your resource has been created'
          self.headers.merge!({ 'X-Custom' => 'OK' })
        end
      end
    end
  end
end

Since Actions are now immutable, those operations needed to move to an ephemeral response object.

2 Likes