Hello, Qiita!! This article is about "The process of creating a new app with Rails 6". From Rails6, nice packages such as webpack and yarn will appear ~~ I don't understand ~~. I think there are many people who are addicted to building an environment (I am an example). I was able to build the environment with Docker, but since my understanding of Docker is too rough, I will post about the process in the local environment.
By the way, I'm a beginner who recently started making RoR apps. Please watch with warm eyes. : flushed:
I have also posted an article on Rails 5, so if you are interested, please see here.
We will create an app in the above environment! : sunglasses:
On the terminal
rbenv local 2.7.1
After executing
rails _6.0.3_ new app_name -d mysql -B
To execute.
rbenv
rbenv command execution declarationlocal 2.7.1
Specify the version of Ruby used in this project (ver.2.7.1 this time)rails
Declaration of rails command execution_6.0.3_
Specify version of ruby (ver.6.0.3 this time)new
New app creation commandapp_name
Definition of the name of the app you want to make-d mysql
Specify the database you want to use (mysql this time) -B
Instructions to skip bundle install
For the usage and mechanism of rbenv, please refer to the following article because it is easy to understand. _ How to use and how rbenv works--Qiita _
If you do rails new
on the terminal as above, many folders and files will be created. (The same content as Rails 5 is omitted.)
Babel.config.js
node_modules
yarn.lock
Yarn is a Node.js (JavaScript) package manager jointly developed by Facebook, Google, etc. ↑ I didn't know, it's amazing (no vocabulary): innocent:
Yarn itself is also a Node module package.
Originally, Node.js has a package manager called npm (Node Package Manager), but compared to npm, Yarn is
--Node module installation is very fast --There is a function that makes the same version no matter who makes it (version lock function) --Increased security --Command line output is simple and easy to read
It has the following features.
Rails has a Gem package manager called Bundler, but it's like its JavaScript version.
javascript/webpack
Before rails5, the javascript folder was placed under app / assets. In rails6, it is under app.
Webpack starts from the specified file, connects the files from there to the Imozuru formula relying on the import statement, and outputs the combined JavaScript file.
This bundling process is called a bundle. And the tool for bundling is called bundler.
The point seems to be that "basic functions are combined into one JavaScript file".
The description of rails in Gemfile,
Gemfile
~
gem 'rails', '6.0.3'
~
Fix it with the version you want to use (ver.6.0.3 this time).
I skipped the gem installation with the -B
command earlier, so on the terminal
bundle install
To execute.
Let's actually start the server! On the terminal
rails s
To execute.
rails server
Instructions to connect Rails application created by rails new
command to server in local environment
rails server
_ can be _rails s
_ but OK _: ok_hand:
If the following log is displayed on the terminal, the connection with the server is complete!
Use Ctrl-C to stop
Let's check it on your browser! Go to [localhost: 3000](http: // localhost: 3000)!
I was able to connect to the server! : metal:
Thank you for watching until the end. During my research, I learned that Ruby is a scripting language and Javascript is an interpreter language. As I explore the history of programming languages, I am deeply moved by the fact that various languages and frameworks are the accumulation of human wisdom. : thinking:
Also, in the future, I would like to write an article about how to add functions using various gems.
If you have any questions regarding this article, please let us know.
I've been feeling unpleasant with mask acne recently, so I think skin care is also important. : mask:
See you again! : walking_tone1:
Completely manage JS and CSS with webpack in Rails environment Understanding the basics of webpack and Babel Samurai blog
Recommended Posts