Skip to content

Commit

Permalink
Added layout links (with routes)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhartl committed Aug 16, 2010
1 parent 2562b2a commit 41fc4b3
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 270 deletions.
4 changes: 4 additions & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ def contact
def about
@title = "About"
end

def help
@title = "Help"
end
end
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ def title
"#{base_title} | #{@title}"
end
end

def logo
image_tag("logo.png", :alt => "Sample App", :class => "round")
end
end
4 changes: 2 additions & 2 deletions app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<footer>
<nav class="round">
<ul>
<li><%= link_to "About", '#' %></li>
<li><%= link_to "Contact", '#' %></li>
<li><%= link_to "About", about_path %></li>
<li><%= link_to "Contact", contact_path %></li>
<li><%= link_to "News", 'http://news.railstutorial.org/' %></li>
<li><%= link_to "Rails Tutorial", 'http://railstutorial.org/' %></li>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<header>
<%= image_tag("logo.png", :alt => "Sample App", :class => "round") %>
<%= link_to logo, root_path %>
<nav class="round">
<ul>
<li><%= link_to "Home", '#' %></li>
<li><%= link_to "Help", '#' %></li>
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "Help", help_path %></li>
<li><%= link_to "Sign in", '#' %></li>
</ul>
</nav>
Expand Down
7 changes: 7 additions & 0 deletions app/views/pages/help.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>Help</h1>
<p>
Get help on Ruby on Rails Tutorial at the
<a href="http://railstutorial.org/help">Rails Tutorial help page</a>.
To get help on this sample app, see the
<a href="http://railstutorial.org/book">Rails Tutorial book</a>.
</p>
10 changes: 7 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
SampleApp::Application.routes.draw do
get "pages/home"
get "pages/contact"
get "pages/about"

root :to => "pages#home"

match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'


# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down
262 changes: 0 additions & 262 deletions public/index.html

This file was deleted.

4 changes: 4 additions & 0 deletions public/stylesheets/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ section {
background: #fff;
}

section h1 {
font-size: 200%;
}

/* Links */

a {
Expand Down
13 changes: 13 additions & 0 deletions spec/controllers/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,17 @@
:content => "#{@base_title} | About")
end
end

describe "GET 'help'" do
it "should be successful" do
get 'help'
response.should be_success
end

it "should have the right title" do
get 'help'
response.should have_selector("title",
:content => "#{@base_title} | Help")
end
end
end
24 changes: 24 additions & 0 deletions spec/requests/layout_links_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'

describe "LayoutLinks" do

it "should have a Home page at '/'" do
get '/'
response.should have_selector('title', :content => "Home")
end

it "should have a Contact page at '/contact'" do
get '/contact'
response.should have_selector('title', :content => "Contact")
end

it "should have an About page at '/about'" do
get '/about'
response.should have_selector('title', :content => "About")
end

it "should a Help page at '/help'" do
get '/help'
response.should have_selector('title', :content => "Help")
end
end

0 comments on commit 41fc4b3

Please sign in to comment.