LoginSignup
3
3

More than 5 years have passed since last update.

Deviseでパスワードリセット用メールが全てid=1のユーザーに送られてしまう

Last updated at Posted at 2016-01-11

パスワードのリセットがうまくいかない

WebBrickのログみたらこんななってた

  User Load (0.2ms)  SELECT  "users".* FROM "users"  ORDER BY "users"."id" ASC LIMIT 1
  User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."reset_password_token" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["reset_password_token", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]]

う、うん。。。
とりあえず時間ないので以下の方法で対応した。

controllerを生成

rails g devise:controllers users

app/controllers/users/passwords_controller.rbを編集

passwords_controller.rb
def create
    # self.resource = resource_class.send_reset_password_instructions(resource_params)
    self.resource = User.where(:email => resource_params['email']).send_reset_password_instructions(resource_params)


    logger.debug self.resource.inspect
    yield resource if block_given?

    if successfully_sent?(resource)
      respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
    else
      respond_with(resource)
    end
  end

これで一応うまくいったんだけど自分でこう書かないとパスワードリセットできないのかな....

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3