Rails Tutorial Memorandum (Chapter 3, 3.3.2)

environment

macOS Catalina 10.15.5 Rails 6.0.3

I'll write a Rails tutorial and a lot of it. The tutorial is compliant with the 6th edition because I want to get used to Github.

3.3.2 Red I want to display the view from the URL/static_pages/about. In what order do you check from $ rails t?

Conclusion

① Create a URL in config/routes.rb ② Create about action in app/controllers/static_pages_controller.rb ③ Create about.html.erb (view) in app/views/static_pages

Overview

test added

test/controllers/static_pages_controller_test.rb


test "should get about" do
    get static_pages_about_url
    assert_response :success
  end
end

$ rails t

NameError: undefined local variable or method `static_pages_about_url'

"Cannot find` static_pages_about_url'(URL) " ↓ ① Create a URL in routes.rb

config/routes.rb


get  'static_pages/about'

(When a GET request comes to the URL/static_pages/about, pass it to the about action of the StaticPages controller) ↓ $ rails t

AbstractController::ActionNotFound:
The action 'about' could not be found for StaticPagesController

"Static Pages controller has no about action" ↓ ② Create about action in static_pages_controller.rb

app/controllers/static_pages_controller.rb


def about
end

$ rails t

ActionController::MissingExactTemplate: 
StaticPagesController#about is missing a template for request formats: text/html

"There is no about template in StaticPagesController" ↓ ③ Create about.html.erb in app/views/static_pages (Because the template = data in views, for example, the about action is associated with the view about.html.erb. This time it is a view related to static_pages, so put it in the corresponding folder)

The file was created when I ran $ touch app/views/static_pages/about.html.erb. ↓ $ rails t The result is green.

Recommended Posts

Rails Tutorial Memorandum (Chapter 3, 3.1)
Rails Tutorial Memorandum (Chapter 3, 3.3.2)
rails tutorial Chapter 6
rails tutorial Chapter 1
Rails tutorial memorandum 1
Rails tutorial memorandum 2
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 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
Rails Tutorial Records and Memorandum # 0
Rails memorandum
rails tutorial
rails tutorial
rails tutorial
[Rails tutorial] A memorandum of "Chapter 11 Account Activation"
rails tutorial
rails tutorial
[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)
Rails Tutorial (4th Edition) Memo Chapter 6
Rails tutorial test
Start Rails Tutorial
[Beginner] Rails Tutorial
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 Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapter 6
Chapter 4 Rails Flavored Ruby
[Rails Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapter 3
Cloud9 is out of memory: Rails tutorial memorandum
Rails Tutorial cheat sheet
Rails version upgrade memorandum 5.0 → 5.1
[Rails] Learning with Rails tutorial
Chewing Rails Tutorial [Chapter 3 Creating Almost Static Pages]
Resolve Gem :: FilePermissionError when running gem install rails (Rails Tutorial Chapter 1)
Rails Tutorial 4th Edition: Chapter 1 From Zero to Deployment
Resolve ActiveRecord :: NoDatabaseError when doing rails test (Rails tutorial Chapter 3)
11.1 AccountActivations Resources: Rails Tutorial Notes-Chapter 11
I tried Rails beginner [Chapter 1]
Rails Tutorial (4th Edition) Summary
[Rails] Rails version upgrade error memorandum
I tried Rails beginner [Chapter 2]
[Rails] Implementation of tutorial function