article blog.rubyonrails.ba
Hanami and Ruby on Rails: A Side-by-Side Look at Command Line Tools 15/03/2023 ~ Views: 997
When it comes to web application development in Ruby, two frameworks come to mind - Ruby on Rails and Hanami. Both frameworks have their own unique features and strengths that can make them ideal for different use cases. In this article, we will compare the commands used in Hanami and Ruby on Rails.

Ruby on Rails (RoR) is a popular web framework that was released in 2005. It follows the Model-View-Controller (MVC) architecture pattern and is built on top of the Ruby programming language. RoR is known for its convention over configuration approach and its ability to rapidly develop web applications.

On the other hand, Hanami is a newer framework that was released in 2016. It also follows the MVC pattern but differs from RoR in many ways. Hanami prioritizes modularity, simplicity, and flexibility. It is also known for its architecture and design patterns, which help developers create scalable and maintainable applications.

Here is a list of commonly used commands in both Hanami and Ruby on Rails:

Creating a new project

To create a new project in Ruby on Rails, you can use the following command:

rails new project_name 

This command generates a new Rails project with a default file structure and installs all necessary dependencies.

In Hanami, you can use the following command to create a new project:

hanami new project_name 

This command generates a new Hanami project with a default file structure and installs all necessary dependencies.

Generating a model

To generate a new model in Ruby on Rails, you can use the following command:

rails generate model ModelName attribute:type

This command generates a new model with the specified name and attributes.

In Hanami, you can use the following command to generate a new model:

hanami generate model ModelName attribute:type

This command generates a new model with the specified name and attributes.

Generating a controller

To generate a new controller in Ruby on Rails, you can use the following command:

rails generate controller ControllerName 

This command generates a new controller with the specified name.

In Hanami, you can use the following command to generate a new controller:

hanami generate action ControllerName actionName 

This command generates a new controller and an action with the specified names.

Generating a view

To generate a new view in Ruby on Rails, you can use the following command:

rails generate view ControllerName ActionName 

This command generates a new view for the specified action in the specified controller.

In Hanami, you can use the following command to generate a new view:

hanami generate view ControllerName ActionName 

This command generates a new view for the specified action in the specified controller.

Database migrations

To create a new database migration in Ruby on Rails, you can use the following command:

rails generate migration MigrationName 

This command generates a new migration file with the specified name, which you can use to make changes to the database schema.

In Hanami, you can use the following command to create a new migration:

hanami generate migration MigrationName 

This command generates a new migration file with the specified name, which you can use to make changes to the database schema.

To run the migrations in both frameworks, you can use the following commands:

rails db:migrate 
hanami db migrate 

These commands apply any pending migrations to the database.

Server

To start a local server in Ruby on Rails, you can use the following command:

rails server

This command starts a local server at localhost:3000, which you can use to test your application.

In Hanami, you can use the following command to start a local server:

hanami server 

This command also starts a local server at localhost:2300 by default.

Console

To access the application console in Ruby on Rails, you can use the following command:

rails console

This command starts an interactive console that allows you to execute Ruby code in the context of your application.

In Hanami, you can use the following command to start the application console:

hanami console

This command starts an interactive console that allows you to execute Ruby code in the context of your application.

Routes

To view the routes in Ruby on Rails, you can use the following command:

rails routes 

This command displays a list of all the routes in your application.

In Hanami, you can use the following command to view the routes:

hanami routes 

This command displays a list of all the routes in your application.

Testing

Both frameworks provide testing frameworks that allow you to write tests for your application. In Ruby on Rails, the default testing framework is called RSpec. To run the tests, you can use the following command:

rspec 

In Hanami, the default testing framework is called Minitest. To run the tests, you can use the following command:

hanami test

Conclusion

In conclusion, both Hanami and Ruby on Rails provide a set of commands that can be used to develop web applications. While some commands are similar, others are unique to each framework. Ultimately, the choice between Hanami and Ruby on Rails depends on the specific requirements of the project and the preferences of the developer.

Tags: #hanami #ruby #rails #command #tools #web #development #comparison #chatgpt

Back

OPEN TO HIRE
yes blog.rubyonrails.ba
Nezir Zahirovic
Ruby On Rails Full stack last 8 years.
C#, ASP.NET, JavaScript, SQL, CSS, Bootstrap 11 years.

Top articles

What's the Fucking Clean Code??? >>>
The Hidden Costs of 'Cheap' Software Agencies: When Low H... >>>
Sharing 2 free tickets for Ruby Global Summit 2023 >>>
300,000 Downloads and a Few Mistakes: My Journey as an An... >>>
I was successful in building a company worth 2 million wi... >>>