Rename get "/"
route to “root”
This commit refactors the Request Routing layer of our application to
name the GET /
route.
By passing as: "root"
as an option to the get "/"
declaration, the
routing configuration will declare root_path
and root_url
helper
methods that will be available in the application’s controllers and view
templates.
When the tests are run again, they’re still passing.
Collapse config/routes.rb
Expand config/routes.rb
config/routes.rb
diff --git a/config/routes.rb b/config/routes.rb
index 00736b9..c80813a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -2,5 +2,5 @@ Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
resources :notes, only: [:new, :create]
- get "/", controller: "notes", action: "index"
+ get "/", controller: "notes", action: "index", as: "root"
end
Collapse test/system/user_shares_a_message_test.rb
Expand test/system/user_shares_a_message_test.rb
test/system/user_shares_a_message_test.rb
diff --git a/test/system/user_shares_a_message_test.rb b/test/system/user_shares_a_message_test.rb
index e1817fa..f66c5b1 100644
--- a/test/system/user_shares_a_message_test.rb
+++ b/test/system/user_shares_a_message_test.rb
@@ -4,7 +4,7 @@ class UserSharesAMessageTest < ApplicationSystemTestCase
test "visiting the index" do
content = "Hello, World!"
- visit "/"
+ visit root_path
click_on "Share a Note"
fill_in "Message", with: content
click_on "Share"