new hanami_blog –database=postgres –template=haml – test=rspec • Will build the skeleton of the app and basic config based on the options you passed. Very similar to Rails.
each "service" is located • Holds specific, assets, controllers, views, templates routes, and config for a 'service' • Config folder • Holds initializers and environment configuration • DB folder • Holds migration files and schema file
Creates Post entity and Post repository • Bundle exec hanami g migration create_posts • Creates a migration file to create the posts table • Manually write migration and run hanami db prepare • From Hanami 1.0 migration will be created as part of the model generator
Responsible for the domain logic • The core of the application • Repository • An object that mediates between entities and persistence layer • Storage independent • Exposes just a few query methods
web posts#index • Creates Posts#index action class and spec • Creates Posts index view class • Creates posts/index.html.haml template • Inserts get '/posts', to: 'posts#index' to routes.rb • Everything is created in the context of the Web app
Each action is its own class with a call method • Sets status code and the headers for the response • Differently from Rails, the router instantiates the action itself and send the call method to it.
body of the action response • Is used as a context for the templates. All methods declared in the view are available to the template • It exposes helpers, like the form, and routes • Can be used to simplify templates
Validations can also be added to controllers to validate the passed params • Useful when an entity has 2 or more different validation, depending on workflow