[Rails Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapter 3

Introduction

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.

Controller generation command

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.

Model generation command

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.

test

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.

  1. Write the failing test first
  2. Write the application code and make it successful (pass the test)
  3. Refactor if necessary This is what is called a test drive cycle.

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.

At the end

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

[Rails Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapter 6
[Rails Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapter 3
[Rails Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapters 4 and 5
[Rails Struggle/Rails Tutorial] Summary of Rails Tutorial Chapter 2
rails tutorial Chapter 1
rails tutorial Chapter 7
rails tutorial Chapter 5
rails tutorial Chapter 10
rails tutorial Chapter 9
rails tutorial Chapter 8
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
Rails Tutorial Chapter 5 Notes
Rails Tutorial Chapter 10 Notes
Rails Tutorial Chapter 3 Notes
Rails Tutorial Chapter 3 Learning
Rails Tutorial Memorandum (Chapter 3, 3.1)
Rails Tutorial Chapter 4 Notes
Rails Tutorial Chapter 4 Learning
Rails Tutorial Chapter 1 Learning
Rails Tutorial Chapter 2 Learning
Rails Tutorial Chapter 8 Notes
Rails Tutorial Memorandum (Chapter 3, 3.3.2)
[Ruby on Rails Tutorial] Error in the test in Chapter 3
What you learned about hashes
What you learned about symbols
[Rails Tutorial Chapter 4] Rails-flavored Ruby
What I learned from studying Rails
[Rails Tutorial Chapter 5] Create a layout
rails tutorial chapter 10 summary (for self-learning)
Chewing Rails Tutorial [Chapter 2 Toy Application]
Rails Tutorial (4th Edition) Memo Chapter 6
What to do if the Rails page doesn't appear in Rails tutorial 1.3.2
What to do if Cloud9 is full in the Rails tutorial
[Note] What to do if bundle install in Chapter 3 of the rails tutorial is not possible
Rails Tutorial 6th Edition Learning Summary Chapter 10
Rails Tutorial 6th Edition Learning Summary Chapter 7
Rails Tutorial 6th Edition Learning Summary Chapter 4
rails tutorial
Rails Tutorial 6th Edition Learning Summary Chapter 9
Rails Tutorial 6th Edition Learning Summary Chapter 6
What is follow_redirect! Following ?: Rails Tutorial Memorandum-Chapter 7
[Rails Struggle/Rails Tutorial] Summary of Heroku commands
Rails Tutorial 6th Edition Learning Summary Chapter 5
Rails refactoring story learned in the field
rails tutorial
What Rails beginners learned by solving errors
rails tutorial
How to use MySQL in Rails tutorial
rails tutorial
Rails Tutorial 6th Edition Learning Summary Chapter 2
Rails Tutorial Chapter 0: Preliminary Basic Knowledge Learning 5
What to do if you can't bundle update and bundle install after installing Ruby 3.0.0 in the Rails tutorial
rails tutorial
Rails Tutorial 6th Edition Learning Summary Chapter 3
rails tutorial
[Cloud9] Yay! You ’re on Rails! Is not displayed in the rails tutorial
rails tutorial
Rails Tutorial 6th Edition Learning Summary Chapter 8
(Giri) A local government employee in his twenties works on a Rails tutorial [Chapter 11]
Decompose "$ printf" install: --no-document \ nupdate: --no-document \ n ">> ~ / .gemrc" in Chapter 1 of the Rails Tutorial
(Giri) A local government employee in his twenties works on a Rails tutorial [Chapter 1]