Now that you’ve done Chapter 1 of the Rails Tutorial, let’s look back at what we did and what we failed. I’ll take a closer look, so I hope you’ll take a look at the tutorial.
*This article uses Rails Tutorial 4th Edition. Currently, Rails Tutorial 6th Edition is available. Note at the time of the following release https://note.com/yasslab/n/n1543187c3ed6?magazine_key=md778735d3f77
By the way, you can change the typeface to read Mincho or Gothic, though it is a detailed matter. I made it gothic so it’s much easier to read, so I think you should change it to your liking.
In addition, we will create a new application in Chapter 2, so it is okay if you can not deploy in this chapter.
1.1.1 Prerequisite knowledge
The Rails tutorial introduces related courses on Progete, I feel that this really should be done. The command line and Git course are introduced in Chapter 1, I thought “I can go later” and ended up with 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
Describe and install the default contents in the Gemfile by specifying the version.
$ cd hello_app/ $ bundle install
If it doesn’t work, run
1.3.2 rails sever
$ cd ~/environment/hello_app/ Move to #hello_app directory $ rails server # start server
Please note that this terminal will be updated in real time after starting rails server. If you preview the screen, Rails page will be !!Yay!
A 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: Receives input and converts it into model and view commands
- -Quoted from Wikipedia
One question here. Rails uses this MVC architectural pattern. “I’m using 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 could not understand the contents well, but I found that there are other than MVC, of course! Programming is amazing when I think that I am already free from the structure I will study this detailed content again.
In order to display Hello, world! without passing the view, the following code is written.
def hello render html: "hello, world!" end
I thought that the render method would be used like
render("folder name"/"file name"), but you can also use it like this.
[Use Rails Guide 2.2 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, anything can be output 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@example.com
Please note that the name and email address here will be open to the public in the future.
Describe the following contents in the terminal to create a repository
$ git init #Git initialization $ git add -A # add all files in current directory # Staging after adding files, waiting for commit $ git status #Check current staging $ git commit -m "Initialize repository" # Reflect to repository with comments $ git log # View commit message history
What is a repository? It was like that, but it was very easy to understand after reading this. [[Learn by Illustration] Git and GitHub Glossary for Beginners] (https://zukulog098r.com/git/)
Update the source code to Gitbucket. The great advantage is that you can collaborate with other developers.
What is the “public/encryption key” in the procedure? For the time being, I tried to make it as it was told, but I do not understand it well, so I checked it.
When exchanging data via the Internet, encryption is necessary to prevent the information from being stolen. That is why public key cryptography was born. The keys correspond to each other. ・Data encrypted with the public key cannot be returned to the original with the private key (encryption key) ・Data encrypted with a private key (encryption key) is a public key and cannot be recovered
Anyone can see the public key. The sender of the data obtains the information using the public key, encrypts it, and sends it. The receiving side can recover and view the information encrypted with the private key (encryption key) that no one can see. No one else can see the information.
Since this method is used, 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 topic branch for temporary use $ git branch # check all local branches $ git commit -a -m "Improve the README file" # commit all file changes in bulk $ 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 features comparable to commercial databases and the flexibility of open source usage are attractive. https://lets.postgresql.jp/map/intro
A relational database is like a table, it’s like a collection of related data. Still difficult https://aws.amazon.com/jp/relational-database/
Add SQLite and install.
Also, install and deploy Heroku.
$ heroku --version #Verify if Heroku is installed and version $ source <(curl -sL https://cdn.learnenough.com/heroku_install) #Install Heroku on cloud IDE $ heroku login --interactive $ heroku keys:add $ heroku create #Create a new application on Heroku $ git push heroku master #deploy to Heroku
This is the end of Chapter 1.
I wanted to put a log, but the deployment didn’t work.
Thinking later, I think I made the wrong branch and didn’t quite understand that Heroku needed to access from the address generated by
It’s been a long time, but thank you for reading this far. If you have any mistakes, please let me know.