I was thinking of making something in earnest, so I finished building the Rails 6 environment in the development environment. By the way, the article I referred to is -Steps for building a Ruby on Rails environment with Docker [Rails 6 compatible] --Qiita
For other parts that didn't work, ・ Rails6 + MySQL + Nginx + Unicorn + Docker environment construction memo --Qiita -Rails (Docker) can no longer connect to PostgreSQL (Docker), so I checked it. (Could not translate host name "db" to address: Name or service not known) --Qiita
I referred to the above article.
And this time, I stumbled a little at the beginning of the elementary course, so I will talk a little about it.
I wanted to make a top page with rails,
Terminal
$ rails g controller home top
Enter, Then ...
Output result
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
With the help of Google Translate ↓ __ Rails is not currently installed on this system. To get the latest version, enter $ sudo gem install rails. __
Hmmm, why is Rails 6 definitely installed? I was worried about 0.5 seconds, but the answer was simple.
First of all, what is Docker?
Docker is open source software or an open platform for developing, deploying, and executing applications using container virtualization. Docker isolates applications from the development / execution environment by OS-level virtualization using container virtualization, enabling quick application delivery. Moreover, the environment itself can be managed as a code (image) in the same way as an application. By using Docker for development, testing, and deployment, the time gap between "writing code" and "code is executed as a product" can be greatly reduced. Quote: Docker-Wikipedia
As you can see from wikipedia, Docker is a virtualization technology. In other words, I installed Rails using docker-compose, but now I can use it within Docker! It's good to recognize about __.
So __Rails is not currently installed on this system. To get the latest version, enter $ sudo gem install rails. It became __!
Terminal
$ docker-compose run web
This is a magical spell.
After this, if you add the previous command ...
Terminal
$ docker-compose run web rails g contoller home top
Output result
Starting guminoki_db_1 ... done
Could not find generator 'contoller'. Maybe you meant "controller"?
Run `rails generate --help` for more options.
This seems to be a typo in the controller, so start over.
Terminal
$ docker-compose run web rails g contoroller home top
Output result
Starting guminoki_db_1 ... done
create app/controllers/home_controller.rb
route get 'home/top'
invoke erb
create app/views/home
create app/views/home/top.html.erb
invoke test_unit
create test/controllers/home_controller_test.rb
invoke helper
create app/helpers/home_helper.rb
invoke test_unit
invoke assets
invoke scss
create app/assets/stylesheets/home.scss
It's done! You did it!
Previously, I also used __ $ docker-compose run web__ when writing applications in Django. I completely forgot (sweat)
Django development server startup example
$ docker-compose run web python3 manage.py runserver
In addition
Terminal
$ docker-compose run --rm web rails g contoroller home top
If you add the --rm option like this, the container will be deleted automatically when the container is closed, which is very convenient.
Recommended Posts