・ Rails tutorial is the 4th edition ・ This study is the 3rd lap (2nd lap after Chapter 9) ・ The author is a beginner who has done all of Progate.
・ If you read it, you will not understand it. ・ Search and summarize terms that you do not understand (at the bottom of the article, glossary). ・ Dive into what you do not understand. ・ Work on all exercises. ・ Do not copy chords as much as possible.
Chapter 3 where the main sample_app finally begins. From this chapter, I will add today's BGM to accompany my learning. Please for a change. Hitsujibungaku "It was a human"
When I install the gem file, I get a deficit error immediately, but if I bundle update and install it again, it will be solved. And there is another error when deploying to heroku. ** Precompiling assets failed ** is in red. Since it is precompiled, is it an error before compiling? Even if you follow the log and check the part where the error is thrown, ** NoMethodError: undefined method ʻaction_mailer'**? After all, I couldn't find out even after checking it, so I rewrote the gem file again and bundle updated it, and it was able to deploy successfully.
Check if Bitbucket correctly renders the Markdown notation README (List 3.3) as HTML. → In my case, it was Github, but it was drawn correctly (image omitted).
Access the root URL of your production environment (Heroku) and see if the deployment was successful. → hello, world! Was displayed.
Memo 1: ** Column 3.1 How to restore ** The generated code and how to restore the migration are posted. Note 2: Four basic HTTP operations ⇨ GET, POST, PATCH, DELETE
$ rails g controller Foo bar baz
$ rails destroy controller Foo bar baz
The test that finally came. At first I didn't understand it, but now I can understand it a little. The point is to write and confirm the expected movement first, "This works, right ?? (Or, this doesn't work, right ??)". In order to write a test, you need to draw the blueprint of the app first (which may be obvious). If you write "later" in column 3.3, it's only for code whose behavioral specifications aren't settled or are likely to change again soon. Basically, it seems to be based on writing "first". You may want to read the Rails Guide Testing Guide for the details of the test. It's a huge amount, so I'll look at it one by one. Some types of assertions are also listed. I will summarize what appears in this tutorial in the glossary below the article. I think I can remember that better.
static_pages_controller_test.rb
test "should get contact" do
get static_pages_contact_url
assert_response :success
assert_select 'title', "Contact | #{@base_title}"
end
Add contact to the routing, add the contact action to the controller, create a view page and enter Listing 3.40 to pass the test.
routes.rb
Rails.application.routes.draw do
get 'static_pages/home'
get 'static_pages/help'
get 'static_pages/about'
get 'static_pages/contact'
root 'application#hello'
end
static_pages_controller
def contact
end
ruby:contact.html.erb
<% provide(:title, "Contact") %>
<h1>Contact</h1>
<p>
Contact the Ruby on Rails Tutorial about the sample app at the
<a href="https://railstutorial.jp/contact">contact page</a>.
</p>
static_pages_controller_test.rb
test "should get root" do
get root_url
assert_response :success
end
2. Actually, since I wrote the code in Listing 3.41, the test for the previous task should already be green. In such cases, it is difficult to determine whether the test was successful before the change or whether it became successful after the change. To see if the code in Listing 3.41 is affecting the test results, comment out the root routing as shown in Listing 3.43 and see if it turns red (note that Ruby's commenting feature). Will be explained in 4.2.1). Finally, let's undo the commented out part (that is, back to Listing 3.41) and make sure the test turns green. → Certainly, the test results will change before and after commenting out.
-Create a series of (almost) static pages that are the basis of web applications. Since it is not RESTful, each routing is set individually. ・ Basically, write the test first. It is important to draw the expected movement firmly in your head. ・ If you maintain the test, you can rest assured when refactoring. -The common parts of the view can be summarized in /layouts/application.html.erb. -Variables defined in the controller can be used in the ERB file.
Next, let's go to Chapter 4
⇨ Go to Chapter 4! ⇦ Click here for Chapter 2 Click here for premise and author status for learning
-Compile Translate from human to machine language. It seems that the program we wrote needs to be converted so that it can be understood because it cannot be understood directly on the computer side.
・ Refactoring Organize the internal structure of the source code without changing the behavior seen from the outside of the program. It's important to test each refactoring.
・ SEO (Search Engine Optimization) SEO measures = Display at the top of search results. Important in web marketing.
・ Assert_response Claim that the response has a specific status code. If you specify: success, you have specified status code 200-299. (Status Code List)
・ Assert_select Checks if a given element meets the criteria. It might be a convenient assertion. There are two formats. For more information, go to the Rails Guide. ](Https://railsguides.jp/testing.html)
Recommended Posts