visit
$rails generate model model-name
$rails generate controller controller-name
When we create a controller, it automatically creates an empty view folder called the same way. It is possible to define or add methods in the same command as it is shown on the next command, where we create a controller called homes.
$rails generate controller Homes contact info
. which creates the methods contact and info in the controller’s class, at the same time it creates the routes, the views contact, and info in the folder app/views/homes/.$rails generate scaffold name parameter
this command is really useful to create a restful controller, it means it has the methods index, new, edit, show, create, update, and destroy. At the same time, it creates the views, index, new, show, edit, the model, the migration with the parameters listed at the end of the command, and resources routes.
The example above generates the Posts controller, the Post model, the migration with the attributes title string type, and body text type.
$rails db:migrate
One of the first things you want to do is to see how the app is working on the browser, for this purpose you can use the command $rails server or $rails s, which launches the server by default on the port 3000 but if you want to use a different port you can add -p and the new port number,
$rails server -p 4000
$ rails new . - -database=postgresql
$rails new . - -database=mysql
Which generates some lines on the file config/database.yml, setting up the chosen database type.
In general terms, I can say that ruby on rails is an excellent framework to work with, of course, you can find more frameworks based on different programming languages, like Laravel which is based on PHP; in my opinion, I have found easier to work with rails, but the logic is about the same, so when you master a framework like this one, it would be easy to learn a new one.Previously published at //medium.com/@javiercaliescali/what-you-need-to-know-about-ruby-on-rails-to-start-your-first-app-417c00f32d94