<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 3.6 練習 從這以后,我建議在單獨的主題分支中做練習: ``` $ git checkout static-pages $ git checkout -b static-pages-exercises ``` 這么做就不會和本書正文產生沖突了。 練習做完后,可以把相應的分支推送到遠程倉庫中(如果有遠程倉庫的話): ``` # 做完第一個練習后 $ git commit -am "Eliminate repetition (solves exercise 3.1)" # 做完第二個練習后 $ git add -A $ git commit -m "Add a Contact page (solves exercise 3.2)" $ git push -u origin static-pages-exercises $ git checkout master ``` (為了繼續后面的開發,最后一步只切換到主分支,但不合并,以免和正文產生沖突。)在后面的章節中,使用的分支和提交消息有所不同,但基本思想是一致的。 電子書中有練習的答案,如果想閱讀參考答案,請[購買電子書](http://railstutorial-china.org/#purchase)。 1. 你可能注意到了,靜態頁面控制器的測試([代碼清單 3.22](#listing-title-tests))中有些重復,每個標題測試中都有“Ruby on Rails Tutorial Sample App”。我們要使用特殊的函數 `setup` 去除重復。這個函數在每個測試運行之前執行。請你確認[代碼清單 3.38](#listing-base-title-test) 中的測試仍能通過。([代碼清單 3.38](#listing-base-title-test) 中使用了一個實例變量,[2.2.2 節](chapter2.html#mvc-in-action)簡單介紹過,[4.4.5 節](chapter4.html#a-user-class)會進一步介紹。這段代碼中還使用了字符串插值操作,[4.2.2 節](chapter4.html#strings)會做介紹。) 2. 為這個演示應用添加一個“聯系”頁面。[[14](#fn-14)]參照[代碼清單 3.13](#listing-about-test),先編寫一個測試,檢查頁面的標題是否為 “Contact | Ruby on Rails Tutorial Sample App”,從而確定 /static_pages/contact 對應的頁面是否存在。把[代碼清單 3.39](#listing-proposed-contact-page) 中的內容寫入“聯系”頁面的視圖,讓測試通過。注意,這個練習是獨立的,所以[代碼清單 3.39](#listing-proposed-contact-page) 中的代碼不會影響[代碼清單 3.38](#listing-base-title-test) 中的測試。 ##### 代碼清單 3.38:使用通用標題的靜態頁面控制器測試 GREEN test/controllers/static_pages_controller_test.rb ``` require 'test_helper' class StaticPagesControllerTest < ActionController::TestCase def setup @base_title = "Ruby on Rails Tutorial Sample App" end test "should get home" do get :home assert_response :success assert_select "title", "Home | #{@base_title}" end test "should get help" do get :help assert_response :success assert_select "title", "Help | #{@base_title}" end test "should get about" do get :about assert_response :success assert_select "title", "About | #{@base_title}" end end ``` ##### 代碼清單 3.39:“聯系”頁面的內容 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> ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看