なるようになるブログ

読書感想文かrailsについてかrubyについてか

rails commit log流し読み(2022/06/19)

2022/06/19分のコミットです。

CHANGELOGへの追加はありませんでした。


Fix docs for ActionController::Metal#headers

Action Packのdocの修正です。ActionController::Metal#headersのdocからメンションしているメソッドやattributeのリンク先が壊れていたりdocが不足していたりしたのを修正しています。


Fix minor errata on debugging section [ci-skip]

rails guideのDebugging Rails Applicationsの修正です。

各箇所の言い回し等を修正しています。


Add ActiveRecord::Base::generates_token_for (#44189)

Active Recordの修正です。

任意のrecordの値を使用してのtokenの生成、及び、そのtokenを使用してのfind処理を行えるよう修正しています。tokenの生成はgenerates_token_forメソッドで、そのtokenを使用してのfindはfind_by_token_forメソッドでそれぞれ行えるようになっています。

class User < ActiveRecord::Base
  has_secure_password

  generates_token_for :password_reset do
    # BCrypt salt changes when password is updated
    BCrypt::Password.new(password_digest).salt[-10..]
  end
end

user = User.first
token = user.generate_token_for(:password_reset)

User.find_by_token_for(:password_reset, token) # => user

user.update!(password: "new password")
User.find_by_token_for(:password_reset, token) # => nil