[Practice]
⇒Please try it as it is.
■ Controller A controller is a container that bundles a collection of (basically dynamic) web pages. → I don't understand a little.
■rails generate controller StaticPages home help Static_pages_controller.rb is generated in the controller. in routes.rb ・ Static_pages / home ・ Static_pages / help Is generated.
At this point, enter "static_pages / home" in the address bar to move. The destination to move to is "home.html.erb" in the view.
■ HTTP method There are four types: GET, POST, PATCH, and DELETE. GET: Call page POST: Used when the user inputs something and sends it. PATCH: Probably used for updates. DELETE: Used for deletion
[Practice]
Try removing the Foo controller and related actions using the techniques introduced in Column 3.1. See column →rails destroy controller Foo bar baz
■ Test case, test suite One test is called a test case. A collection of test cases is called a test suite.
■ Test-driven design A method to proceed with development after writing test code
■static_pages_controller_test.rb It is generated at the same time as rails g.
test/controllers/static_pages_controller_test.rb
test "should get home" do
get static_pages_home_url
assert_response :success
end
This file already inherits ActionDispatch :: IntegrationTest, so I understand that's what it is. Generate a new test called "should get home". Access with "get static_pages_home_url". Judge whether it is successful or not with "assert_response: success".
■touch app/views/static_pages/about.html.erb In the touch app / views / static_pages directory Generate a file about.html.erb.
You can also right-click and select "Create File".
■about.html.erb You don't need
.→ Since this page is being refactored, it's okay to postpone it in the worst case. ■mv app/views/layouts/application.html.erb layout_file Move application.html.erb to layout_file.
■assert_select "title", "Home | Ruby on Rails Tutorial Sample App" Check if the content of the title tag of the page you moved to is "" Home | Ruby on Rails Tutorial Sample App "".
[Practice]
Substitute the string Ruby on Rails Tutorial Sample App for @base_title and We are developing each.
■ Provide method Pass the parameter with the provide method and receive it with the yield method. By unifying the titles, everything except the contents of the
tag is the same.■app/views/layouts/application.html.erb What forms the basis of design.
[Practice]
Create a file called contact.html.erb in static_pages /.
routes.rb
<% 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 contact" do
get static_pages_contact_url
assert_response :success
assert_select "title", "contact | #{@base_title}"
end
routes.rb
get 'static_pages/contact'
static_pages_controller.rb
def contact
end
[Practice]
statc_pages is not needed as root does not belong to any directory
static_pages_controller_test.rb
test "should get root" do
get root_url
assert_response :success
end
Recommended Posts