[RUBY] Rails Tutorial Chapter 1 From Zero to Deployment [Try]

Now that you've done Chapter 1 of the Rails Tutorial, you'll look back at what you did and what you failed. I'll take a closer look, so I'd be happy if you could take a look at the tutorial.

By the way, you can change the reading font to Mincho font or Gothic font. I made it very easy to read in Gothic style, so I think you should change it to your liking.

We'll also create a new app in Chapter 2, so it's okay if you can't deploy in this chapter.

1.1.1 Prerequisite knowledge

The Rails tutorial introduces Progete related courses, I really feel that this should be done. The command line and Git courses are introduced in Chapter 1, I thought, "I can do it later," and after all, I made a mistake in the command, and the app was remade. We recommend that you take this course before you start.

1.2.1 Development environment

Install Cloud9, a cloud IDE

1.2.2 Install Rails

    $ printf "install: --no-document \nupdate:  --no-document\n" >> ~/.gemrc
 $ gem install rails -v 5.1.6 # Specify version with -v
 $ cd ~ / environment # Change to the'environment' directory
    $ rails _5.1.6_ new hello_app

1.3.1 Bundler Describe and install the default contents in the Gemfile by specifying the version.

$ cd hello_app/
$ bundle install

If it doesn't work, run bundle update

1.3.2 rails sever

 $ cd ~ / environment / hello_app / Move to #hello_app directory
 $ rails server # Start server

Please note that after starting the rails server, the inside of this terminal will be updated in real time. When you preview the screen, the Rails page is !! Yay!

1.3.3 Model-View-Controller

The story that each model view controller is involved.

model: application data, business rules, logic, functions view: Arbitrary information representation such as graphs and diagrams controller: Takes input and converts it into instructions for model and view -Quoted from Wikipedia

One question here. Rails has adopted this MVC architectural pattern. "Adopting this pattern" means that there are other patterns ...? I looked it up.

・ Forms and controls ・ Presentation model ・ Application model ・ MVVM ・ Model View Presenter (MVP)

Reference article https://www.atmarkit.co.jp/fdotnet/chushin/greatblogentry_10/greatblogentry_10_01.html

I couldn't understand the contents well, but I found out that there are other than MVC, of course! Programming is amazing when I think that it is free from the structure I will study this detailed content as well.

1.3.4 Hello,wold!

The following code is written to display Hello, world! Without passing through the view.

 def hello
    render html: "hello, world!"

I thought that the render method would be used like render ("folder name" / "file name") , but you can also use it like this.

[Rails Guide 2.2 Use render](https://railsguides.jp/layouts_and_rendering.html#render%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%99%E3% 82% 8B) According to the Rails guide, you can output anything anymore.

Set the routing and display it in the browser.

1.4.1 Installation and setup

From here, we will enable version control with Git.

$ git config --global user.name "Your Name"
$ git config --global user.email [email protected]

Please note that the name and email address here will be open to the public in the future.

In order to create a repository, write the following contents in the terminal

 $ git init # Git initialization
 $ git add -A # Add all files in the current directory
# Staged after file addition, waiting for commit
 $ git status #Check current staging
 $ git commit -m "Initialize repository" #Reflect with comment in repository
 $ git log # View commit message history

What is a repository suddenly? It was like that, but it was very easy to understand when I read this. [[Remember with illustrations] Git and GitHub terminology for beginners] (https://zukulog098r.com/git/)

1.4.3 Gitbucket Update the source code to Gitbucket. The big advantage is that you can collaborate with other developers.

What is the "public key / encryption key" in the procedure? For the time being, I tried to make it as it was said, but I'm not sure, so I looked it up.

When exchanging data via the Internet, encryption is required to prevent information from being stolen. That's why public key cryptography was born. This key corresponds to each other. -Data encrypted with a public key cannot be restored with a private key (encryption key). -Data encrypted with a private key (encryption key) cannot be restored with a public key.

Anyone can see the public key. The side that sends the data acquires the information with the public key, encrypts it, and sends it. The recipient can restore and view the information encrypted with the private key (encryption key) that is not shown to anyone. This will prevent the information from being seen by a third party.

Because of this method, it is necessary to enter the public key for exchanging information.

Reference article https://railstutorial.jp/chapters/beginning?version=5.1#sec-bundler

1.4.4 Branch, edit, commit, merge

 $ git checkout -b modify-README #Create a topic branch for temporary use
 $ git branch # Check all local branches
 $ git commit -a -m "Improve the README file" # Commit all file changes at once
 $ git checkout master #move to master branch
 $ git merge modify-README Merge topic branch modify-README into #master branch
 $ git push #push

1.5.1 Heroku setup

Heroku says it uses a PostgreSQL database, What is PostgreSQL ...

PostgreSQL is an open source relational database. Full-fledged functions comparable to commercial databases and flexibility of use unique to open source are attractive. https://lets.postgresql.jp/map/intro

A relational database is a table type and seems to be a collection of associated data. Still difficult https://aws.amazon.com/jp/relational-database/

Add SQLite and install.

Also, install and deploy Heroku.

 $ heroku --version Check if #Heroku is installed and version
 $ source <(curl -sL https://cdn.learnenough.com/heroku_install) #Install Heroku on your cloud IDE
$ heroku login --interactive
$ heroku keys:add
 $ heroku create #Create a new application on Heroku
 Deploy to $ git push heroku master #Heroku

This is the end of Chapter 1. I wanted to post a log, but the deployment didn't work. When I think about it later, I think it's because I made a mistake in creating the branch and Heroku didn't quite understand that it needed to be accessed from the address generated by heroku create.

It's been a long time, but thank you for reading this far. If you have any mistakes, please let me know.

Recommended Posts

Rails Tutorial Chapter 1 From Zero to Deployment [Try]
Rails Tutorial 4th Edition: Chapter 1 From Zero to Deployment
Chewing Rails Tutorial [Chapter 1 From Zero to Deployment] Second Half
Chewing Rails Tutorial [Chapter 1 From Zero to Deployment] First Half
rails tutorial Chapter 6
rails tutorial Chapter 1
rails tutorial Chapter 7
rails tutorial Chapter 5
rails tutorial Chapter 10
rails tutorial Chapter 9
rails tutorial Chapter 8
Rails Tutorial Chapter 5 Notes
Rails Tutorial Chapter 10 Notes
Rails Tutorial Chapter 3 Notes
Rails Tutorial Chapter 3 Learning
Rails Tutorial Memorandum (Chapter 3, 3.1)
Rails Tutorial record and memorandum # 1 "From installation to hello_app deployment + error handling"
Rails Tutorial Chapter 4 Notes
Rails Tutorial Chapter 4 Learning
Rails Tutorial Chapter 1 Learning
Rails Tutorial Chapter 2 Learning
Rails Tutorial Chapter 8 Notes
Rails Tutorial Memorandum (Chapter 3, 3.3.2)
Try Spring Boot from 0 to 100.
[Rails Tutorial Chapter 4] Rails-flavored Ruby
[Rails Struggle/Rails Tutorial] Summary of Rails Tutorial Chapter 2
[Rails Tutorial Chapter 5] Create a layout
rails tutorial chapter 10 summary (for self-learning)
Chewing Rails Tutorial [Chapter 2 Toy Application]
Rails Tutorial (4th Edition) Memo Chapter 6
[Rails tutorial] Cannot deploy to Heroku/Change from hello, world to hola, mundo
From pulling docker-image of rails to launching
Rails Tutorial 6th Edition Learning Summary Chapter 10
Rails Tutorial 6th Edition Learning Summary Chapter 7
Rails Tutorial 6th Edition Learning Summary Chapter 4
rails tutorial
[Rails] How to convert from erb to haml
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
How to use MySQL in Rails tutorial
rails tutorial
Try moving WildFly wild-from installation to deployment-
[Rails] Assigning variables from controller to JavaScript
Rails Tutorial 6th Edition Learning Summary Chapter 2
Rails Tutorial Chapter 0: Preliminary Basic Knowledge Learning 5
Try deploying Rails app to EC2-Part 2 (Deploy)-
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
[Rails Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapter 6
[Rails] I tried to raise the Rails version from 5.0 to 5.2
How to link Rails6 Vue (from environment construction)
[Rails Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapter 3
Try deploying Rails application to EC2-Part 2 (Server construction)-
I want to play with Firestore from Rails