Created
May 10, 2012 18:00
-
-
Save alexch/2654771 to your computer and use it in GitHub Desktop.
important parts of chapter 4 of railstutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Listing 4.3. The sample application site layout. | |
# app/views/layouts/application.html.erb | |
<title><%= full_title(yield(:title)) %></title> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Listing 4.2. Defining a full_title helper. | |
# app/helpers/application_helper.rb | |
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 | |
# Listing 4.4. Updated tests for the Home page’s title. | |
# spec/requests/static_pages_spec.rb | |
(see book) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Listing 4.5. The Home page with no custom page title. | |
# app/views/static_pages/home.html.erb | |
<h1>Sample App</h1> | |
<p> | |
This is the home page for the | |
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> | |
sample application. | |
</p> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment