"Hello everyone, good evening"
(... I wanted to say it once)
I'm a beginner who recently started making RoR apps. Since this is Qiita's first post, I would like to post about the insanely rudimentary "process of creating a new app with Rails"! : writing_hand:
We will create an app in the above environment! : fist:
On the terminal
rbenv local 2.5.1
rails _5.2.3_ new app_name --database=mysql --skip-bundle
To execute.
rbenv
rbenv command execution declarationlocal 2.5.1
Specify the version of Ruby used in this project (this time ver.5.2.3)rails
Declaration of rails command execution_5.2.3_
Specify version of ruby (ver.5.2.3 this time)new
New app creation commandapp_name
Definition of the name of the app you want to make--database=mysql
Specify the database you want to use (mysql this time) --skip-bundle
Instructions to skip bundle install
- If ʻapp_name
_ is _
.`_, it will be created on the current directory _--database = mysql
_ is OK with-d mysql
_: ok_hand:--skip-bundle
_ can be-B
but _: ok_hand:
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 contents should look like this:
app
It contains the application's controllers, models, views, helpers, mailers, channels, jobs, and assets.
bin
Contains script files such as Rails scripts for launching, updating, and deploying applications.
config
The application's configuration files (routing, database, etc.) are located here.
db
It contains the current database schema and database migration files.
lib
Contains extension modules used by the application.
log
Contains the application log files.
public
The files under this folder can be viewed directly from the outside (Internet). Place static files and compiled assets here.
storage
Contains Active Storage files used by the Disk service.
test
Place test related files such as Unit tests and fixtures here.
tmp
Temporary files such as cache and pid are placed.
vendor
All code written by third parties is placed here. For a normal Rails application, put the external gem file here.
.gitignore
Specify a file (or pattern) that is not registered in Git in this file.
.ruby-version
The default Ruby version is specified in this file.
config.ru
A Rack configuration file for Rack-based servers that you need to launch your application.
Gemfile
Describes the gem dependencies required by your Rails application. This file is used by the Bundler gem.
package.json
You can specify the npm dependencies required by your Rails application in this file. This file is used by Yarn.
Rakefile
This file describes the tasks that you can perform from the command line. The task definition here is defined for the Rails-wide components.
If you want to define your own Rake task, writing it directly in Rakefile is too powerful, so try to add a file for Rake under the lib / tasks folder as much as possible.
README.md
Fill in the manual here to give an overview of the application. It is necessary to fill in this file with the application setting method etc. so that anyone can build the application by reading this.
Gem in Ruby has the following two roles.
By using the package, development can proceed efficiently, so it seems that it is often used in the actual field. Since the package can be installed easily, even beginners of Ruby on Rails can quickly equip it with full-scale application functions. : relaxed:
Gemfile with the function you want to use in the app
Gemfile
gem 'gem name'
It is described as. (Here, I will omit the specific types of gems.)
Also, the description of rails in the Gemfile,
Gemfile
~
gem 'rails', '5.2.3'
~
Fix it with the version you want to use (ver.5.2.3 this time).
I skipped the gem installation with the --skip-bundle
command earlier, so on the terminal
bundle install
To execute.
bundle install
Command to install gem according to the contents of Gemfile using gem called bundlerLet's actually start the server! On the terminal
rails server
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!
=> Booting Puma
=> Rails 5.2.3 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.6 (ruby 2.5.1-p57), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
Let's check it on your browser! Go to localhost: 3000 (localhost: 3000).
You have successfully connected to the server! : sunglasses:
Thank you for watching until the end. In the future, I'd like to write articles about how to register users with devise and how to build a RoR environment on Docker (it is undecided when).
Also, if you have any questions regarding this article, please let us know. As an engineer, I want to start running as soon as possible. : walking_tone 1:: walking_tone 1:: walking_tone 1: Well then!
Recommended Posts