Contact page

現在繼續把 Contact 頁面做完,加入測試(Red):

test "should get contact" do
  get :contact
  assert_response :success
  assert_select "title", "Contact | Ruby on Rails Tutorial Sample App"
end

執行測試,會失敗(Red):

$ bundle exec rake test

缺了路由、action、view,一一補完:

config/routes.rb

get  'static_pages/contact'

app/controllers/static_pages_controller.rb

class StaticPagesController < ApplicationController
  .
  .
  .
  def contact
  end
end

app/views/static_pages/contact.html.erb

<% provide(:title, 'Contact') %>
<h1>Contact</h1>
<p>
  Contact the Ruby on Rails Tutorial about the sample app at the
  <a href="http://www.railstutorial.org/#contact">contact page</a>.
</p>

再度執行測試,成功(Green):

$ bundle exec rake test