Skip to content

Commit bedccd4

Browse files
committed
Add a full_title helper
1 parent 00e5c6d commit bedccd4

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

app/helpers/application_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
module ApplicationHelper
2+
3+
# Returns the full title on a per-page basis.
4+
def full_title(page_title = '')
5+
base_title = "Ruby on Rails Tutorial Sample App"
6+
if page_title.empty?
7+
base_title
8+
else
9+
page_title + " | " + base_title
10+
end
11+
end
212
end

app/views/layouts/application.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title><%= yield(:title) %> | Ruby on Rails Tutorial Sample App</title>
4+
<title><%= full_title(yield(:title)) %></title>
55
<meta name="viewport" content="width=device-width,initial-scale=1">
66
<meta charset="utf-8">
77
<%= csrf_meta_tags %>

app/views/static_pages/home.html.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<% provide(:title, "Home") %>
21
<h1>Sample App</h1>
32
<p>
43
This is the home page for the

test/controllers/static_pages_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class StaticPagesControllerTest < ActionDispatch::IntegrationTest
55
test "should get home" do
66
get static_pages_home_url
77
assert_response :success
8-
assert_select "title", "Home | Ruby on Rails Tutorial Sample App"
8+
assert_select "title", "Ruby on Rails Tutorial Sample App"
99
end
1010

1111
test "should get help" do

0 commit comments

Comments
 (0)