You've finished Chapter 3 of the Rails Tutorial. After getting into practice, I learned about the routing controller view and the tests. As I learned, I have summarized the contents that can be used in practice.
The command to generate the controller is as follows.
$rails g controller (controller name) (action name)
Action names can be specified together in the generate script. In the Rails tutorial, the action names are home, help, and about.
If you have already generated a controller with a command, for example if you misspelled the controller name, you might consider deleting each file. So what should I do? In such a case, the following command is a convenient command, and you can delete the generated controller file at once.
$rails destroy controller (controller name) (action name)
With this alone, you can delete the generated controller file and restore it.
In the same way as the controller generation, hit the following command to generate the model.
$rails g model (model name) (column name):Data type)
If you want to restore the model that has already been generated before generating it, type the following command.
$rails destroy model (model name)
If you want to delete the model, you don't need the argument after the model name.
There are three Rails tutorials: controller testing (chapter 3), model testing (chapter 6), and integration testing (chapter 7). The tests are performed in the following order.
minitest reporters minitest-reporters are one of the gems, and making them available makes it easier to see test successes and failures. RSpec is the mainstream for Rails testing, but in the Rails tutorial, I'll do it to the end with a mini test.
Guard After setting Guard, type the following command.
$ bundle exec guard
If you change the file of the controller by executing the command, the test of the controller will be executed automatically. If you want to end the command, you can press Ctrl + D to end it. Since test automation is really convenient, I thought in Qiita that it would be better to finish the initial settings early so that I could concentrate on development.
The above is the summary of Chapter 3 of the Rails tutorial. I have summarized in Qiita what I can put to practical use in my work. After finishing each chapter like this, I would like to summarize where to live in practice.
Recommended Posts