[RUBY] A summary of only Rails tutorial setup related

I've finally gone around the Rails tutorial. As the next step, I've summarized only the setup related items in order to create an original Web service while referring to the Rails tutorial. The development environment is Cloud9.

Building Rails environment

Convenient command

A command (apparently) that specifies not to install documents on a regular basis. I was allowed to reference. [Disassemble "$ printf" install: --no-document \ nupdate: --no-document \ n ">> ~ / .gemrc" in Chapter 1 of the Rails tutorial](https://qiita.com/nodenanode/ items / 11a34144533654a5c024)

$ printf "install: --no-document \nupdate:  --no-document\n" >> ~/.gemrc

Rails installation

This time, I left the version as a tutorial, but I have to upgrade it someday. .. ..

$ gem install rails -v 5.1.6

Run rails new

$ rails _5.1.6_ new "title"

Build a GitHub environment

Generate git

$ cd ~/envronment/"title"
$ git init
$ git add -A
$ git commit -m "Initialize repository" #Comments are standard

Create repository (GitHub)

After creating a repository with'New repository'on GitHub, execute the following command (URL is described in the repository creation screen)

$ git remote add origin "URL"
$ git push -u origin master

#Set origin master as upstream branch with u option
#From the next time, you can push to origin master only with git push

If you want to keep the repository private, click Make private in the'Danger Zone'at the bottom of the Setting.

SSH public key settings (GitHub)

$ cd ~/.ssh          #Move to the folder to put the key
$ ssh-keygen -t rsa  #Generate key
$ cat id_rsa.pub     #View the contents of the key and copy manually

#I couldn't use pbcopy in cloud9, so I'm copying it manually.

Set public key at https://github.com/settings/ssh Check the connection with the following command, and if the following comment appears, the connection is complete.

$ ssh -T [email protected]

Hi (account name)! You've successfully authenticated, but GitHub does not provide shell access.

I was allowed to reference. Procedure for ssh connection on GitHub ~ From generation of public / private key ~

What to do if a warning appears

You may get the following warning (I got it). Warning: Permanently added the RSA host key for IP address 'xxx.xxx.xxx.x' to the list of known hosts.

It doesn't mean that you can't push, so there seems to be no problem, but it's unpleasant to see Worning. .. .. The following command updates the contents of known_hosts and Worning disappears.

$ ssh-keygen -R "IP address"

#If the above doesn't help, try the following commands as well

$ ssh-keygen -R github.com
How to avoid being asked for a password every time you push
  1. Click the "Clone or download" button on the right side of the Code screen on GitHub
  2. Click "Use SSH" in the upper right and copy the displayed URL
  3. Execute the following command from the terminal
$ git remote set-url origin "URL"

#Do the following for confirmation
$ git remote -v

#Git as [email protected] if it starts from com!
origin  [email protected]:reiji012-pg/Tabetter.git (fetch)
origin  [email protected]:reiji012-pg/Tabetter.git (push)

Heroku setup

For the time being, leave the tutorial as it is. Install PostgreSQL gem only in production environment

Gemfile.


group :production do
  gem 'pg', '0.20.0'
end

Install SQLite gem in development and test environment

Gemfile.


group :development, :test do
  gem 'sqlite3', '1.3.13'
  gem 'byebug',  '9.0.6', platform: :mri
end

Install with options not to install pg gem in production environment

$ bundle install --without production

Install Heroku

$ source <(curl -sL https://cdn.learnenough.com/heroku_install)

After confirming the installation, from login to deployment.

$ heroku --version
$ heroku login --interactive
$ heroku keys:add
$ heroku create
$ git push heroku master

You can change the name of the application with the following command

$ heroku rename "Application name"

Heroku commands are no longer available

Heroku settings disappear every time I start the terminal It can be solved by setting the file that describes the path to heroku to be executed every time the terminal is started. Insert all of the following with the vi command at the bottom of the file

~/.bashrc


PATH=/usr/local/heroku/bin:$PATH

~/.bash_profile


source ~/.bashrc

SSL settings in production environment

Modify the following files (commented out, just uncomment)

config/environments/production.rb


config.force_ssl = true

Replace Heroku's web server with Puma from the default WEBrick (Because it cannot handle significant traffic and is not suitable for production environments)

Just uncomment what is also commented out

config/puma.rb


on_worker_boot do
  ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end

This is a new file (./Procfile)

web: bundle exec puma -C config/puma.rb

For the time being, I think we have created an environment where we can start creating applications.

Recommended Posts

A summary of only Rails tutorial setup related
[Rails Struggle/Rails Tutorial] Summary of Rails Tutorial Chapter 2
[Rails Struggle/Rails Tutorial] Summary of Heroku commands
[Rails tutorial] A memorandum of "Chapter 11 Account Activation"
A brief summary of Rails association options (foreign_key, primary_key)
Rails Tutorial (4th Edition) Summary
[Rails] Implementation of tutorial function
Summary of rails validation (for myself)
[Rails Tutorial Chapter 5] Create a layout
rails tutorial chapter 10 summary (for self-learning)
[Rails] Summary of complicated routing configurations
Rails Tutorial 6th Edition Learning Summary Chapter 10
Rails Tutorial Chapter 14 was completed, and it took a total of 155.5 hours.
Rails Tutorial 6th Edition Learning Summary Chapter 4
Summary of stumbling blocks related to form_with
rails tutorial
Rails Tutorial 6th Edition Learning Summary Chapter 9
Rails Tutorial 6th Edition Learning Summary Chapter 6
Rails Tutorial 6th Edition Learning Summary Chapter 5
rails tutorial
rails tutorial
rails tutorial
Rails Tutorial 6th Edition Learning Summary Chapter 2
Rails Basics of creating a new application
Rails: A little summary about data types
rails tutorial
Rails Tutorial 6th Edition Learning Summary Chapter 3
rails tutorial
rails tutorial
Rails Tutorial 6th Edition Learning Summary Chapter 8
[Ruby on Rails] Rails tutorial Chapter 14 Summary of how to implement the status feed
A brief summary of Bootstrap features for beginners
Summary of basic knowledge of Rails acquired by progate
Cloud9 is out of memory: Rails tutorial memorandum
Summary of execution order such as spock setup
[Ruby on Rails] A memorandum of layout templates
[Note] Summary of rails login function using devise ①
rails tutorial Chapter 6
Rails tutorial test
Java related summary
rails tutorial Chapter 1
Rails tutorial memorandum 1
Rails tutorial memorandum 2
I tried to make a message function of Rails Tutorial extension (Part 1): Create a model
rails tutorial Chapter 7
rails tutorial Chapter 5
rails tutorial Chapter 10
Rails 6.0 Routing Summary
rails tutorial Chapter 9
rails tutorial Chapter 8
Start Rails Tutorial
rails db: 〇〇 Summary
[Beginner] Rails Tutorial
Summary of frequently used commands in Rails and Docker
A review of the code used by rails beginners
One case of solving a migration error in Rails
[Java Silver] Summary of points related to lambda expressions
Rails tutorial (6th edition) Background operation of profile editing
[Rails] Volume that displays favorites and a list of favorites
[IOS] To allow rotation of only a specific screen
Rails Tutorial Extension: I created a follower notification function