<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 6.4 小結 本章從零開始建立了一個可以正常使用的用戶模型,創建了 `name`、`email` 和 `password` 屬性,還為這些屬性制定了重要的取值約束規則。而且,已經可以使用密碼對用戶進行認證了。整個用戶模型只用了十行代碼。 在接下來的[第 7 章](chapter7.html#sign-up),我們會創建一個注冊表單,用來新建用戶,還會創建一個頁面,顯示用戶的信息。[第 8 章](chapter8.html#log-in-log-out)會使用 [6.3 節](#adding-a-secure-password)實現的認證機制讓用戶登錄網站。 如果使用 Git,而且一直都沒提交,現在是提交的好時機: ``` $ bundle exec rake test $ git add -A $ git commit -m "Make a basic User model (including secure passwords)" ``` 然后合并到主分支,再推送到遠程倉庫中: ``` $ git checkout master $ git merge modeling-users $ git push ``` 為了讓用戶模型在生產環境中能正常使用,我們要在 Heroku 中執行遷移。這個操作可以通過 `heroku run` 命令完成: ``` $ bundle exec rake test $ git push heroku $ heroku run rake db:migrate ``` 我們可以在生產環境的控制臺中執行以下代碼確認一下: ``` $ heroku run console --sandbox >> User.create(name: "Michael Hartl", email: "michael@example.com", ?> password: "foobar", password_confirmation: "foobar") => #<User id: 1, name: "Michael Hartl", email: "michael@example.com", created_at: "2014-08-29 03:27:50", updated_at: "2014-08-29 03:27:50", password_digest: "$2a$10$IViF0Q5j3hsEVgHgrrKH3uDou86Ka2lEPz8zkwQopwj..."> ``` ## 6.4.1 讀完本章學到了什么 * 使用遷移可以修改應用的數據模型; * Active Record 提供了很多創建和處理數據模型的方法; * 使用 Active Record 驗證可以在模型的數據上添加約束條件; * 常見的驗證有存在性、長度和格式; * 正則表達式晦澀難懂,但功能強大; * 數據庫索引可以提升查詢效率,而且能在數據庫層實現唯一性約束; * 可以使用內置的 `has_secure_password` 方法在模型中添加一個安全的密碼。
                  <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>

                              哎呀哎呀视频在线观看