[RUBY] Rails Tutorial Chapter 1 Learning

Where I thought (.´ ・ ω ・) in the first chapter of Rails Tutorial

Cloud9 user registration

Cloud9 is now integrated with Amazon Web Services (AWS), so you'll need an AWS account to use Cloud9. If you already have an AWS account, please log in to AWS. Go to the AWS console and type “Cloud9” in the search box to go to the page for creating a Cloud9 development environment. If you don't have an Amazon Web Services (AWS) account, register as an AWS Cloud9 user. Credit card information is now required to prevent abuse, but rest assured that the Rails tutorial workspace is free for one year. It can take up to 24 hours for the account to be activated, but for the author it took about 10 minutes. When you reach the Cloud9 management page (Figure 1.4), click “Create environment” and proceed until you see the screen shown in Figure 1.5. You can finally get the Cloud9 development environment by entering the information as appropriate and pressing the confirmation button to proceed (Fig. 1.6). At this time, a warning message saying that you are the “root” user may be displayed, but we will explain how to deal with this later (I will explain how to deal with it using the function called IAM in 13.4.4). Quote: https://railstutorial.jp/chapters/beginning?version=5.1#sec-development_environment

I didn't feel like this, so I referred to Video explaining how to register cloud9 on Youtube.

Credit card required to register for AWS Cloud9 For those who don't think so much but can't make credit cards (´-ω-`) You can use the debit card you get by opening an account at Sumishin SBI Net Bank ('ω')

How do I open a file with the command? Solve

#Install useful c9 for Rails tutorial('ω')No
#c9 <file name>You can open the file with.
npm install -g c9

What is this command doing? Part 1

Added to avoid wasting time installing Ruby
$ echo "gem: --no-document" >> ~/.gemrc

UNIX command processing
echo "gem: --no-document" ("gem: --no-document)
>> (Please add it at the end.)
~/.gemrc file(Under your home directory~/.In a file called gemrc)

What is this command doing? Part 2

Install Yarn to manage JavaScript software dependencies
$ source <(curl -sL https://cdn.learnenough.com/yarn_install)

UNIX command processing
A command to execute the command written in the source file in the current shell
<() :Process substitution(Ability to handle command output results as a file)

curl -sL https://cdn.learnenough.com/yarn_install
curl [http://Target URL]Make an HTTP request and output the result to standard output
-s --Do not output extra
-L --If there is a redirect, get the redirect destination information

yarn_The contents of the install file.
#!/bin/bash

# Installs YARN on AWS Cloud9 Ubuntu Server.
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get -y update && sudo apt-get -y install yarn

Finally I could see the whole picture! You are executing the following command ...!
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get -y update && sudo apt-get -y install yarn

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get -y update && sudo apt-get -y install yarn

What is this ...? Yarn installation procedure for your platform image.png

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get -y update && sudo apt-get -y install yarn

It was a command to install Yarn, which manages dependencies of JavaScript software.

What is this command doing? Part 3

sudo ln -sf `which nano` /usr/bin

UNIX command processing
Run as sudo administrator
ln -sf symbolic link(Shortcut)Create

/usr/Create a shortcut named which nano that jumps to the location bin?

If you use the cloud IDE, then set the default editor to use with Git (used for editing and modifying the project with “amend”). For now, let's use the nano editor, which is relatively easy to use and is also the default editor for cloud IDEs. Even if you write this setting, the default editor will log out when you log out, and the path is incorrect, so execute to create a symbolic link (also called a symlink) so that it points to the nano executable file correctly. Let's (it's a little difficult for beginners, so don't worry if you can't read and understand it now).

(.'・ Ω ・) Hmm? What should I do? Well, do you want to skip it (^ ω ^) ...

About database software (SQL) used in Rails Tutorial

Use sqlite in cloud9 (development environment). Heroku uses PostgreSQL. It is recommended to use the same SQL for the development environment and the production environment.

I wonder why they are using it for learning. (´-ω-`) I don't know.

AWS Free Tier on Amazon RDS For Amazon RDS Single-AZ db.t2.micro instances that use MySQL, MariaDB, PostgreSQL, Oracle BYOL, or SQL Server (SQL Server Express Edition), enough to run DB instances consecutively each month. 750 hours of usage time for Use of the Oracle BYOL db.t3.micro Single-AZ instance is included in the Amazon RDS free tier. If you run both instances of db.t2.micro Single-AZ and db.t3.micro Single-AZ on Oracle BYOL, their usage is totaled across the instance classes. 20 GB general purpose (SSD) DB storage * 20 GB backup storage for automatic database backups and any DB snapshot by the user *

I can use PostgreSQL ... why? .. ..

Rails installation related

Install Rails Use the gem command provided by RubyGems.
gem install rails -v 6.0.3
gem install [App] -v [Version specification]
#Empty template creation command in Rails
rails _6.0.3_ new hello_app
rails _[version]_ new [app name]

Gemfile.Is the library to install(parts)File that describes


source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.3'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster.
# Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a
  # debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console'
  # anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the
  # background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
#Command to install all libraries listed in Gemfile
bundle install

#Commands to use if there is a dependency problem with the installed library
bundle update
#Rails server launch command
rails server
rails s #(Abbreviation)← This one is used more often

rb config/environments/development.rb



Rails.application.configure do
  .
  .
  .
  #Allow connection to Cloud9
  config.hosts.clear ← If you do not add this, it will be played by accessing the Rails server
end

Git related

Git is a convenient app for managing source code Github is a service that provides a place to store source code on the Internet

#Name settings and email address settings used in Git
#* Please note that the name and email address set in Git will be released to the public on the repository in the future.

$ git config --global user.name "name"
$ git config --global user.email email address

#Allow the checkout command to be omitted for co.
$ git config --global alias.co checkout

#Change the time required for a password when doing git push Reduces the hassle of typing a password every time
$ git config --global credential.helper "cache --timeout=86400"

#Repository(Storage box)Command to make
$ git init

#Command to put files in temporary storage box-A changes(New / Add / Delete)Means to add all the files that were
$ git add -A

#Command to add a memo to the temporary storage box and move it to the storage box-m "message"You can write notes with
$ git commit -m "Initialize repository"

#Register your source code storage on the Internet with the name origin
$ git remote add origin https://github.com/<Your GitHub account name>/hello_app.git

#My upload
$ git push -u origin master

#You can see if there are any changes
$ git status

#Check what you have committed in the past
$ git log

Heroku related

Heroku is a service that allows you to publish apps on the Internet (up to 5 are free) If you use Git for source code version control, you can easily publish your Rails application.

Since the environment is different between the development environment and the production environment, it is necessary to change the library to be installed accordingly. cloud9 (development / test environment) = sqlite3 Heroku (production environment) = PostgreSQL

ruby.Gemfile


source 'https://rubygems.org' 
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'rails',      '6.0.3'
gem 'puma',       '4.3.4'
gem 'sass-rails', '5.1.0'
gem 'webpacker',  '4.0.7'
gem 'turbolinks', '5.2.0'
gem 'jbuilder',   '2.9.1'
gem 'bootsnap',   '1.4.5', require: false

#I think that everything from here onwards will be installed in common('ω')No

#Install only development environment and test environment
group :development, :test do 
  gem 'sqlite3', '1.4.1'
  gem 'byebug',  '11.0.1', platforms: [:mri, :mingw, :x64_mingw]
end

#Install only development environment
group :development do 
  gem 'web-console',           '4.0.1'
  gem 'listen',                '3.1.5'
  gem 'spring',                '2.1.0'
  gem 'spring-watcher-listen', '2.0.1'
end

#Install test environment only
group :test do 
  gem 'capybara',           '3.28.0'
  gem 'selenium-webdriver', '3.142.4'
  gem 'webdrivers',         '4.1.2'
end

#Install only in production environment
group :production do 
  gem 'pg', '1.1.4' 
end

#On Windows tzinfo for timezone information-Must include data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
#Install non-production gems
$ bundle install --without production

If you do not reflect in Gemfile.lock that you added pg gem or specified Ruby version, This is because deploying to a production environment will fail.

#install heroku command
source <(curl -sL https://cdn.learnenough.com/heroku_install)

This is the command inside that is being executed!
curl -OL https://cli-assets.heroku.com/heroku-linux-x64.tar.gz
tar zxf heroku-linux-x64.tar.gz && rm -f heroku-linux-x64.tar.gz
sudo mv heroku /usr/local
echo 'PATH=/usr/local/heroku/bin:$PATH' >> $HOME/.profile
source $HOME/.profile > /dev/null
#Log in to heroku(--You can log in without using a browser using the interactive option)
$ heroku login --interactive

#Create a new application on Heroku(Analyze the git source code and prepare an appropriate server)
$ heroku create 

#Upload the source code. Now the service you created will be published on the net.
$ git push heroku master

Impressions

Hello World using Cloud9, Git, and Heroku, but now we have a public service! I think it's really amazing to be able to publish the service in one chapter while there are many books that end only with application development. I was stumbling on a UNIX command in this output, and I found out that the mystery was solved a little. UNIX command ... (゜-゜) I read the pre-learning source, (process substitution) <(), curl, In Was it written like this ...

Well, let's do our best in Chapter 2 (`) No

Recommended Posts