Skip to content

Instantly share code, notes, and snippets.

@jodosha
Created September 7, 2017 14:34
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jodosha/f427402c705d6603da6edf57a60c3b20 to your computer and use it in GitHub Desktop.
Save jodosha/f427402c705d6603da6edf57a60c3b20 to your computer and use it in GitHub Desktop.
Mount Hanami inside Rails

1. Setup

rails new blog
cd blog
hanami new bookshelf
vim Gemfile # add `hanami`
bundle
vim bookshelf/config/environment.rb # See Note 1

Note 1

# comment this line
# require 'hanami/model'

# comment this block
# mailer do
#  # ...
# end

2. Create an action

cd bookshelf
bundle exec hanami generate action web home#index --url=/
vim apps/web/templates/home/index.html.erb # add <h1>Hello from Hanami</h1>
cd ..

3. Mount Hanami

vim config/environment.rb # see Note 2 
vim config/routes.rb # see Note 3   mount Hanami.app, at: "/bookshelf"

Note 2

require_relative 'application'
require_relative "../bookshelf/config/boot"

# Initialize the Rails application.
Rails.application.initialize!

Note 3

Rails.application.routes.draw do
  mount Hanami.app, at: "/bookshelf"
end

4. Try it!

bundle exec rails server
# visit http://localhost:3000/bookshelf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment