Recently, for some reason, I started studying Ruby on Rails. I would like to talk about the issue that occurred there. As anyone who uses Rails or is studying knows, Rails comes with a test function as standard. It is the one that is automatically created when you create a controller or model. When I was doing a Rails tutorial as a Rails study, there was an incident where it wasn't created. Rails generate controller at the beginning of the tutorial It was when the controller was created with the controller name and action name. I wondered why the test was running on rails t. Make a note of the solution you found at that time.
In config/application.rb in the project
require "rails/test_unit/railtie"
After adding, the test folder was created successfully. Once to try
rails destroy controller controller name action name
Delete with and then again
rails g controller controller name action name
When created with
/myapp # rails g controller Index home help
Running via Spring preloader in process 556
create app/controllers/index_controller.rb
route get 'index/home'
get 'index/help'
invoke erb
create app/views/index
create app/views/index/home.html.erb
create app/views/index/help.html.erb
invoke test_unit
create test/controllers/index_controller_test.rb <-this
invoke helper
create app/helpers/index_helper.rb
invoke test_unit
invoke assets
invoke scss
create app/assets/stylesheets/index.scss
It was created!
By the way
require 'rails/all'
Those who have become should be okay.
I used a different version of Rails from the tutorial, and I built the environment with Docker, so it seems that it did not come to the expected state. I've been googled for ways to solve this problem, but aren't there many people who have the same experience? it seems like. But I learned Rails! It seems that many other settings can be made in application.rb. For example, whether to allow the creation of stylesheets and helpers when generating ... For more information, you may want to read "Set up config.generators first after rails new" (https://qiita.com/yuutetu/items/135b1c8ab512208aebfe).
ruby 2.6.5 Rails 6.1.0
Recommended Posts