Rails Tutorial (4th Edition) Summary

Introduction

I have 11 months of programming experience, and I have the impression that I completed the Rails tutorial (4th edition) in 6 days. Since there were many parts that I could not understand in the first lap (especially after Chapter 9), I thought I would summarize it before doing the second lap, so I will write a memorandum.

By the way, my state before doing the Rails tutorial is as follows.

-With Progate, Command Line / Git / HTML / CSS / Sass / JS / JS (ES5) / jQuery / Node.js / SQL / Ruby / Ruby on Rails5 laps 1-2 times. (Number of total exercises cleared 992 / Number of completed lessons 53 / Lv.296)

-At a programming school, create a post-type web application with an EC site and portfolio by team development using HTML / CSS / Ruby / Rails. -Answer about 100 D / C rank questions in Ruby with Paiza. -Applications created with Rails, homepage: 3 (Implementation function: Post, Like, Comment, Follow, etc.)

Impressions

From Chapter 1 to Chapter 8, I was able to proceed while understanding the whole thing, but from Chapter 9, it became difficult and I could not understand it by reading it once. Even so, I thought it was important to finish it, so I made a note of the parts I didn't understand and proceeded with it. It was a teaching material that required momentum, motivation, and physical strength, but it was very easy to understand because it was written carefully in every detail.

(For example, if the command is written to execute as follows, it will politely tell you "> is automatically output on the terminal, so you do not have to write it.")

Terminal


% XXXXXXXX /
> XXXXXX

How to proceed

I had to move my hands to get it in my head, so I proceeded while moving it in the development environment and production environment. In addition, I proceeded while solving all the exercises.

Summary of each chapter

Each chapter title Time taken
Chapter 1 From zero to deploy 4h30m
Chapter 2 Toy application 2h30m
Chapter 3 Creating almost static pages 2h
Chapter 4 Rails flavored Ruby 11h
Chapter 5 Create a layout 3h
Chapter 6 Create a model of the user 5h
Chapter 7 user registration 4h
Chapter 8 Basic login mechanism 3h30m
Chapter 9 Evolving login mechanism 3h30m
Chapter 10 Update / View / Delete User 3h30m
Chapter 11 Account activation 3h
Chapter 12 Password Reset 3h30m
Chapter 13 User's micro post 3h30m
Chapter 14 Follow users 3h

Total time: 55h30m (approx. 9h/day)

Chapter 1: From zero to deployment

I got stuck in the first installation.

--Number of exercises: 4

** [Error occurred] ** (1) Rails could not be installed by 1.2.2 Installing Rails. Cause: From the error below, you are executing the system Ruby gem command instead of rbenv Ruby.

Terminal


% gem install rails -v 6.0.3  
ERROR: While executing gem ... (Gem::FilePermissionError)
  You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

Execute the following command.

Terminal


% rbenv init
# Load rbenv automatically by appending
# the following to ~/.zshrc:
eval "$(rbenv init -)"

Execute the following command in the terminal to add eval "$ (rbenv init-)" to ~/.zshrc. Installation was successful.

Terminal


% echo 'eval "$(rbenv init -)"' >> ~/.zshrc

② Gem could not be installed As stated in the error statement, it is solved by % bundle update.

Terminal


Bundler could not find compatible versions for gem "selenium-webdriver":
  In Gemfile:
    selenium-webdriver (= 3.142.4)

    webdrivers (= 4.1.2) was resolved to 4.1.2, which depends on
      selenium-webdriver (>= 3.0, < 4.0)

Bundler could not find compatible versions for gem "sprockets":
  In snapshot (Gemfile.lock):
    sprockets (= 4.0.2)

  In Gemfile:
    sass-rails (= 5.1.0) was resolved to 5.1.0, which depends on
      sprockets (>= 2.8, < 4.0)

    rails (~> 6.0.3, >= 6.0.3.4) was resolved to 6.0.3.4, which depends on
      sprockets-rails (>= 2.0.0) was resolved to 3.2.2, which depends on
        sprockets (>= 3.0.0)

Running `bundle update` will rebuild your snapshot from scratch, using
only
the gems in your Gemfile, which may resolve the conflict.

If you have installed a different version of gem (such as Rails' own gem) specified in the Gemfile, run bundle update to update the gem and match the gem version. It would be good.

From the tutorial 3.1 Setup

Chapter 2: Toy Application

I couldn't create a version-specified app and got stuck.

--Number of exercises: 7

** [Error occurred] **

% rails _5.1.6_ new toy_app could not be done Cause: The rails version (5.1.6) specified in the environment was not included. Install the specified version with the following command to solve the problem.

Terminal


% gem install rails -v 5.1.6
% rails _5.1.6_ new toy_app

Chapter 3: Creating Almost Static Pages

Mainly HTMl / CSS / testing. I proceeded without any particular clogging.

--Number of exercises: 5

Chapter 4: Rails-flavored Ruby

There are a lot of things that I don't fully understand, such as objects, classes, instances, and symbols. It was the slowest chapter because I couldn't understand everything at once.

--Number of exercises: 11

** [Error occurred] ** (1) An error occurred because the app used in 4.4.5 User class was changed from toy_app to sample_app. I solved it by changing to toy_app.

** [Difficult to understand / terms / reference articles] **

--About the module --About destructive methods --I don't understand the literal constructor (4.4.1 Constructor is difficult to understand ...)

(Reference article: Rails Tutorial Chapter 4-Learn Rails-flavored Ruby ... Class)

Chapter 5: Create a layout

I proceeded without any particular clogging. It was fun to do it because I could proceed while checking the actual screen.

--Number of exercises: 9

** [Difficult to understand / terms / reference articles] **

--About the asset pipeline

(Reference article: "Asset Pipeline" that Rails beginners can easily trip over)

--About the manifest file --REST concept

Chapter 6: Create a user model

A regular expression came out. I only read the article about regular expressions once, so I thought I had to review it again. I made a lot of mistakes in the exercise.

--Number of exercises: 13

** [Difficult to understand / terms / reference articles] **

--Relational database --Migration --sandbox mode --valid? Method --assertion method -: Unique option --dup (method for duplicating data with the same attributes) --Callback method --digest (originally derived from the term encryption hash function)

Chapter 7: User registration

Some sentences are difficult to understand.

--Number of exercises: 14

** [Difficult to understand / terms / reference articles] **

--Hashing --hexdigest method --aside tag ――English-only text helper called pluralize

Chapter 8: Basic login mechanism

There were many errors due to typos.

--Number of exercises: 10

** [Error occurred] ** (1) The following error occurred. Cause: The path name was wrong.

Terminal


ActionController::RoutingError:         ActionController::RoutingError: No route matches [POST] "/signup"
            test/integration/users_signup_test.rb:7:in `block (2 levels) in <class:UsersSignupTest>'
            test/integration/users_signup_test.rb:6:in `block in <class:UsersSignupTest>'
  19/19: [=====================================================================================] 100% Time: 00:00:00, Time: 00:00:00

Finished in 0.61060s
19 tests, 39 assertions, 0 failures, 1 errors, 0 skips

test/integration/users_signup_test.rb


post users_path, params: {user: {name: "", email: "user@invalid", password:    "foo", password_confirmation: "bar"}}

Nevertheless,

test/integration/users_signup_test.rb


post signup_path, params: {user: {name: "", email: "user@invalid", password:    "foo", password_confirmation: "bar"}}

Was

(2) The following error occurred. Cause: The current_user was just cuttent_user.

ruby:app/views/layouts/_header.html.erb


NameError in Users#show
Showing /Users/XXX/Desktop/Rails_tutorial/environment/sample_app/app/views/layouts/_header.html.erb where line #8 raised:
undefined local variable or method `current_user' for #<#<Class:0x00007fe0eb540190>:0x00007fe0f2883f58>
Did you mean?  cuttent_user

** [Difficult to understand, terms searched, unexpected questions, reference articles] **

--fixure

(Reference article: rails helper basic)

Chapter 9: Evolving Login Mechanism

From here, the terms that I managed to learn in Chapters 1 to 8 frequently occur.

--Number of exercises: 7

** [Difficult to understand, terms searched, unexpected questions, reference articles] **

--Memory digest --Memory token ――What is the difference between model and helper?

Chapter 10: User Update / Display / Delete

The exercise was almost a mistake, and even if I looked at the answer, I couldn't understand it in one go ...

--Number of exercises: 15

** [Error occurred] **

① If you follow the document, you will get an error because there is no user! If you add @ to all, it will be solved. (Reference article: Rails Tutorial Chapter 10 10.32 test does not pass)

def create
    @user = User.find_by(email: params[:session][:email].downcase)
    if @user && @user.authenticate(params[:session][:password])
    log_in @user
    params[:session][:remember_me] == '1' ? remember(@user) : forget(@user)
    redirect_back_or @user
    else
(Omitted)

If you do without @, the following error will occur.

ERROR["test_login_with_remembering", UsersLoginTest, 0.6073389999801293]
 test_login_with_remembering#UsersLoginTest (0.61s)
NoMethodError:         NoMethodError: undefined method `remember_token' for nil:NilClass
            test/integration/users_login_test.rb:43:in `block in <class:UsersLoginTest>'

  30/30: [=====] 100% Time: 00:00:00, Time: 00:00:00

Finished in 0.80407s
30 tests, 82 assertions, 0 failures, 1 errors, 0 skips

** [Difficult to understand, terms searched, unexpected questions, reference articles] **

--Why is the controller _url instead of _path? ?? -toggling! method

Chapter 11: Account Activation

I couldn't understand the mail part at once, but when I checked the operation in Chapter 12, I read Chapter 11 again and understood it better than the first time. Realize the importance of doing it twice or three times.

--Number of exercises: 9

** [Error occurred] **

① <%= form_for(@user, url: yield(:url)) do |f| %>  However, the following error occurred when registering a new user.

image.png

Reference article

-Do you need post'/ signup'? -Rails Tutorial [Chapter 7-8] Routing Error with User Registration

→ Creating/signup of post in Routes.rb is not done in the tutorial, so it may be different.

-[Rails tutorial] Incorrect routing due to partial implementation, the routing error disappeared, but an error occurred in test. Prioritize the resolution of test errors and proceed as it is. Since the routing error was solved again in Chapter 13, I commented out the following.

image.png

Chapter 12: Password reset

I didn't configure heroku to send emails. There were no errors that bothered me for tens of minutes.

--Number of exercises: 9

Chapter 13: User's Micropost

The last exercise was very difficult. I couldn't solve it.

--Number of exercises: 15

** [Difficult to understand, terms searched, unexpected questions, reference articles] **

--How to use default scope ――What is the difference between find and find_by?

Chapter 14: Follow users

The relationship between followers and followers can be organized by examining it once and drawing it on a diagram.

--Number of exercises: 14

** [Error occurred] **

① Application error in heroku. Cause: 13.4.4 When uploading an image in a production environment, an error occurred because the following code was added halfway. After removing that part, I was able to deploy successfully.

app/uploaders/picture_uploader.rb


class PictureUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick
  process resize_to_limit: [400, 400]

  if Rails.env.production?
    storage :fog
  else
    storage :file
  end

The error that occurred below.

Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail

** [Difficult to understand, terms searched, unexpected questions, reference articles] **

--Composite key index -: member method --Philosophy that JavaScript should not be brought to the fore --Status feed

At the end

Those who said, "Let's study programming! Let's use Ruby / Rails as the language! Let's start with the official Rails tutorial!", I thought it would be frustrating. I thought it would be very educational if I did Progate, created an app with Rails, and understood data transfer to some extent (still, I was likely to be frustrated in the second half).

After the second lap, I would like to write an article as "Rails Tutorial (4th Edition) Summary 2". In Summary 2, I think it would be good to talk about the latter half of the chapter in detail.

Reference article (summary)

-Rails Tutorial Chapter 4-Learn Rails Flavored Ruby ... Class -"Asset Pipeline" that Rails beginners can easily trip over -rails helper basic -Rails Tutorial Chapter 10 10.32 test does not pass -Do you need post'/ signup'? -Rails Tutorial [Chapter 7-8] Routing Error with User Registration -[Rails Tutorial] Routing Illegal Due to Partial Implementation

Articles that were very helpful in matching the answers to the exercises

-Blog that disseminates experience and learning as a Kojimano Tech engineer -Physical worker who wants to be an engineer -Ruby on Rails Tutorial Complete Strategy Overview and Exercise Answer Summary

Recommended Posts

Rails Tutorial (4th Edition) Summary
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 6th Edition Learning Summary Chapter 9
Rails Tutorial 6th Edition Learning Summary Chapter 6
Rails Tutorial 6th Edition Learning Summary Chapter 5
Rails Tutorial 6th Edition Learning Summary Chapter 2
Rails Tutorial 6th Edition Learning Summary Chapter 3
Rails Tutorial 6th Edition Learning Summary Chapter 8
Rails Tutorial (4th Edition) Memo Chapter 6
Rails tutorial (6th edition) Follow/unfollow background operation
rails tutorial
rails tutorial
rails tutorial
rails tutorial
Rails Tutorial 4th Edition: Chapter 1 From Zero to Deployment
rails tutorial
rails tutorial
rails tutorial
Rails tutorial (6th edition) Background operation of login function
[Rails Struggle/Rails Tutorial] Summary of Rails Tutorial Chapter 2
rails tutorial chapter 10 summary (for self-learning)
Rails tutorial (6th edition) Background operation of password reset function
rails tutorial Chapter 6
Rails tutorial test
rails tutorial Chapter 1
Rails tutorial memorandum 1
rails tutorial Chapter 7
rails tutorial Chapter 5
rails tutorial Chapter 10
Rails 6.0 Routing Summary
rails tutorial Chapter 9
Rails Tutorial (6th Edition) -Explanation of background operation for each function-
rails tutorial Chapter 8
Start Rails Tutorial
rails db: 〇〇 Summary
[Beginner] Rails Tutorial
Rails tutorial (6th edition) Background operation of the posting function of the micro post
A summary of only Rails tutorial setup related
[Rails] devise-related routing summary
[Rails] Migration command summary
Rails Tutorial Chapter 10 Notes
Rails Tutorial Chapter 3 Notes
Rails Tutorial cheat sheet
Rails Tutorial Chapter 3 Learning
[Rails] Learning with Rails tutorial
[Rails] rails db command summary
Rails Tutorial Memorandum (Chapter 3, 3.1)
rails error resolution summary
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 fighting notes Ⅲ
Rails Tutorial Memorandum (Chapter 3, 3.3.2)
Rails Tutorial Records and Memorandum # 0
[Rails Tutorial Chapter 4] Rails-flavored Ruby
[Rails] Implementation of tutorial function
Ruby on Rails validation summary