Skip to content

Commit

Permalink
User content_for for titles in the application layout (#49702)
Browse files Browse the repository at this point in the history
  • Loading branch information
lazaronixon committed Jan 2, 2024
1 parent 8397eb2 commit 42ca4de
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
@@ -1,3 +1,5 @@
<%% content_for :title, "Editing <%= human_name.downcase %>" %>

<h1>Editing <%= human_name.downcase %></h1>

<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
Expand Down
@@ -1,5 +1,7 @@
<p style="color: green"><%%= notice %></p>

<%% content_for :title, "<%= human_name.pluralize %>" %>

<h1><%= human_name.pluralize %></h1>

<div id="<%= plural_table_name %>">
Expand Down
@@ -1,3 +1,5 @@
<%% content_for :title, "New <%= human_name.downcase %>" %>

<h1>New <%= human_name.downcase %></h1>

<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
Expand Down
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title><%= camelized %></title>
<title><%%= content_for(:title) || "<%= camelized %>" %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%%= csrf_meta_tags %>
<%%= csp_meta_tag %>
Expand Down
2 changes: 1 addition & 1 deletion railties/test/generators/app_generator_test.rb
Expand Up @@ -442,7 +442,7 @@ def test_application_names_are_not_singularized

def test_application_name_is_normalized_in_config
run_generator [File.join(destination_root, "MyWebSite"), "-d", "postgresql"]
assert_file "MyWebSite/app/views/layouts/application.html.erb", /<title>MyWebSite<\/title>/
assert_file "MyWebSite/app/views/layouts/application.html.erb", /<title><%= content_for(:title) || "MyWebSite" %><\/title>/
assert_file "MyWebSite/config/database.yml", /my_web_site_production/
end

Expand Down

0 comments on commit 42ca4de

Please sign in to comment.