Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rails flavour ruby

  • Loading branch information...
commit 536f14f69f394bfc947a67c8402feb33333de6c4 1 parent 8600b46
Mubuntu authored
View
9 app/helpers/application_helper.rb
@@ -1,2 +1,11 @@
module ApplicationHelper
+ # Returns the full title on a per-page basis.
+ def full_title(page_title)
+ base_title = "Ruby on Rails Tutorial Sample App"
+ if page_title.empty?
+ base_title
+ else
+ "#{base_title} | #{page_title}"
+ end
+ end
end
View
2  app/views/layouts/application.html.erb
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
- <title>Ruby on Rails Tutorial Sample App | <%= yield(:title) %></title>
+ <title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
View
1  app/views/static_pages/home.html.erb
@@ -1,4 +1,3 @@
-<% provide(:title, 'Home') %>
<h1>Sample App</h1>
<p>
This is the home page for the
View
9 spec/requests/static_pages_spec.rb
@@ -11,9 +11,14 @@
page.should have_selector('h1', :text => 'Sample App')
end
- it "should have the title 'Home'" do
+ it "should have the base title" do
visit '/static_pages/home'
- page.should have_selector('title', :text => "#{base_title} | Home")
+ page.should have_selector('title', :text => "Ruby on Rails Tutorial Sample App")
+ end
+
+ it "should not have a custom page title" do
+ visit '/static_pages/home'
+ page.should_not have_selector('title', :text => '| Home')
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.