hanami / controller

Complete, fast and testable actions for Rack and Hanami

Home Page:http://hanamirb.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to use it with Rails Router?

jduarte opened this issue · comments

@jodosha could you help us? :)

@jduarte I'd say yes, as hanami actions are rack-compatible

Try doing something like

get 'foo', to: YouHanamiActionClass.new

That is just great, will try that out and write here the outcome! Thanks

@jduarte Hi, just be aware of the fact that Hanami actions are mutable. Our router, creates a new instance of an action for each incoming request. Please make sure to achieve the same behavior with Rails behavior.

Is there any reason why you can't (or won't) use hanami-router for the purpose? If you want to use Hanami actions within the context of a Rails app, you can consider:

class App
  def initialize(&blk)
    @router = Hanami::Router.new(&blk)
  end

  def call(env)
    @router.call(env)
  end
end

And in the Rails router:

mount App.new {
  get "/foo", to: "foo#bar"
}

This is a simplified version of what we do for the DNSimple API v2.

@jodosha this is much cleaner to implement than what I thought. I will start a new project in a few days and I'll surely test it out. I love the way Hanami actions are built as they are much more testable and understandable in the long way when compared to Rails controllers/actions approach but I still need to use Rails as a framework.

Thanks for the insight