0

こんにちは。
Rails でdevise gemを使用しユーザー登録ができるようにしています。

ー現状ー
本番環境はHeroku、Sendgridを使用し、ユーザーの登録時にメール認証を実装。
Googleログインもしたかったので、omniauthableも使用しています。Google経由でサインアップした場合は、メール認証をスキップ。

ーやりたいことー
ユーザーがパスワードを忘れた時にリセット案内メールを送りパスワードの再設定を促すこと

ー困っていることー
パスワードを忘れた場合というリンクから、ユーザーにメールアドレスを入力してもらう。

ユーザーはリセット案内メールを受け取る

メールのリンクからサイトに飛び、パスワードの再設定をする。
※ここで問題が起きています。
新しくパスワードを入力しsubmitすると、トークンが不正というエラーがでます。

色々調べ、DBの中身をと届いたメールを確認すると、
Rails側で作成された、reset password tokenと
メールに届いている reset password tokenが一致していないことに気がつきました。

参考にしたサイト

と同じgemが入っていたので、こちらの方を参考にdevise-i18n-viewsを削除し対応しましたが、変わらず・・・
ここで質問させてもらいます。

ー関係ありそうなコードー
model/user.rb

  devise :database_authenticatable, :registerable,
      :recoverable, :rememberable, :validatable, :confirmable, :omniauthable, omniauth_providers: %i[google_oauth2]

views/users/mailer/reset_password_instructions.html.erb

<%= link_to 'パスワードの変更を行う', edit_password_url(@resource, reset_password_token: @token) %>

config/environments/production.rb

  config.action_mailer.perform_caching = false
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  host = 'https://www.XXXXXXXX.com/'
  config.action_mailer.default_url_options = { host: host }
  ActionMailer::Base.smtp_settings = {
    :address        => 'smtp.sendgrid.net',
    :port           => '587',
    :authentication => :plain,
    :user_name      => ENV['SENDGRID_USERNAME'],
    :password       => ENV['SENDGRID_PASSWORD'],
    :domain         => 'heroku.com',
    :enable_starttls_auto => true
  }

db/schema.rb

  create_table "users", force: :cascade do |t|
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string "username"
    t.string "avatar"
    t.string "confirmation_token"
    t.datetime "confirmed_at"
    t.datetime "confirmation_sent_at"
    t.string "unconfirmed_email"
    t.string "provider"
    t.string "uid"
    t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
    t.index ["email"], name: "index_users_on_email", unique: true
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
  end

何か足りない情報があれば更新します。
どなたかお助けください
よろしくお願いします!

2020/10/19
追記します。
Gemfile

source 'https://rubygems.org'
git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end
gem 'rails', '~> 5.1.4'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'bootstrap'
gem 'simple_form'
gem 'devise-i18n'
gem 'rails-i18n'
gem 'jquery-rails'
gem 'rails-ujs'
gem 'jquery-ui-rails'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'medium-editor-rails'
gem 'medium-editor-insert-plugin-rails'
gem 'carrierwave', '~> 1.3.1'
gem 'cloudinary' , '1.11.1'
gem 'mini_magick'
gem 'acts-as-taggable-on'
gem 'dotenv-rails'
gem 'impressionist', '~>1.6.1'
gem 'enum_help'
gem 'ransack'
gem 'activeadmin'
gem 'meta-tags'
gem 'public_uid'
gem 'friendly_id', '~> 5.2.4'
group :production do
  gem 'pg'
  gem 'heroku-deflater'
end
group :development, :test do
  gem 'byebug', platform: :mri
  gem 'sqlite3', '~> 1.3.6'
  gem 'brakeman', require: false
  gem 'bullet'
end
group :development do
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '~> 3.0.5'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'devise'
gem 'omniauth'
gem 'omniauth-google-oauth2'
gem 'omniauth-facebook'
gem 'sendgrid-ruby'
gem 'mailgun_rails'

gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    actioncable (5.1.7)
      actionpack (= 5.1.7)
      nio4r (~> 2.0)
      websocket-driver (~> 0.6.1)
    actionmailer (5.1.7)
      actionpack (= 5.1.7)
      actionview (= 5.1.7)
      activejob (= 5.1.7)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 2.0)
    actionpack (5.1.7)
      actionview (= 5.1.7)
      activesupport (= 5.1.7)
      rack (~> 2.0)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (5.1.7)
      activesupport (= 5.1.7)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.0.3)
    activeadmin (2.4.0)
      arbre (~> 1.2, >= 1.2.1)
      formtastic (~> 3.1)
      formtastic_i18n (~> 0.4)
      inherited_resources (~> 1.7)
      jquery-rails (~> 4.2)
      kaminari (~> 1.0, >= 1.0.1)
      railties (>= 5.0, < 6.1)
      ransack (~> 2.1, >= 2.1.1)
      sassc-rails (~> 2.1)
      sprockets (>= 3.0, < 4.1)
      sprockets-es6 (~> 0.9, >= 0.9.2)
    activejob (5.1.7)
      activesupport (= 5.1.7)
      globalid (>= 0.3.6)
    activemodel (5.1.7)
      activesupport (= 5.1.7)
    activerecord (5.1.7)
      activemodel (= 5.1.7)
      activesupport (= 5.1.7)
      arel (~> 8.0)
    activesupport (5.1.7)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 0.7, < 2)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
    acts-as-taggable-on (6.5.0)
      activerecord (>= 5.0, < 6.1)
    arbre (1.3.0)
      activesupport (>= 3.0.0, < 6.1)
      ruby2_keywords (>= 0.0.2, < 1.0)
    arel (8.0.0)
    autoprefixer-rails (10.0.0)
      execjs
    aws_cf_signer (0.1.3)
    babel-source (5.8.35)
    babel-transpiler (0.7.0)
      babel-source (>= 4.0, < 6)
      execjs (~> 2.0)
    bcrypt (3.1.16)
    bindex (0.8.1)
    bootstrap (4.5.2)
      autoprefixer-rails (>= 9.1.0)
      popper_js (>= 1.14.3, < 2)
      sassc-rails (>= 2.0.0)
    brakeman (4.9.1)
    builder (3.2.4)
    bullet (6.1.0)
      activesupport (>= 3.0.0)
      uniform_notifier (~> 1.11)
    byebug (11.1.3)
    carrierwave (1.3.1)
      activemodel (>= 4.0.0)
      activesupport (>= 4.0.0)
      mime-types (>= 1.16)
    cloudinary (1.11.1)
      aws_cf_signer
      rest-client
    coffee-rails (4.2.2)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.12.2)
    concurrent-ruby (1.1.7)
    crass (1.0.6)
    devise (4.7.2)
      bcrypt (~> 3.0)
      orm_adapter (~> 0.1)
      railties (>= 4.1.0)
      responders
      warden (~> 1.2.3)
    devise-i18n (1.9.2)
      devise (>= 4.7.1)
    domain_name (0.5.20190701)
      unf (>= 0.0.5, < 1.0.0)
    dotenv (2.7.6)
    dotenv-rails (2.7.6)
      dotenv (= 2.7.6)
      railties (>= 3.2)
    enum_help (0.0.17)
      activesupport (>= 3.0.0)
    erubi (1.9.0)
    execjs (2.7.0)
    faraday (1.0.1)
      multipart-post (>= 1.2, < 3)
    ffi (1.13.1)
    formtastic (3.1.5)
      actionpack (>= 3.2.13)
    formtastic_i18n (0.6.0)
    friendly_id (5.2.5)
      activerecord (>= 4.0.0)
    globalid (0.4.2)
      activesupport (>= 4.2.0)
    has_scope (0.7.2)
      actionpack (>= 4.1)
      activesupport (>= 4.1)
    hashie (4.1.0)
    heroku-deflater (0.6.3)
      rack (>= 1.4.5)
    http-accept (1.7.0)
    http-cookie (1.0.3)
      domain_name (~> 0.5)
    i18n (1.8.5)
      concurrent-ruby (~> 1.0)
    impressionist (1.6.1)
      nokogiri (~> 1)
    inherited_resources (1.11.0)
      actionpack (>= 5.0, < 6.1)
      has_scope (~> 0.6)
      railties (>= 5.0, < 6.1)
      responders (>= 2, < 4)
    jbuilder (2.10.1)
      activesupport (>= 5.0.0)
    jquery-rails (4.4.0)
      rails-dom-testing (>= 1, < 3)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    jquery-ui-rails (6.0.1)
      railties (>= 3.2.16)
    json (2.3.1)
    jwt (2.2.2)
    kaminari (1.2.1)
      activesupport (>= 4.1.0)
      kaminari-actionview (= 1.2.1)
      kaminari-activerecord (= 1.2.1)
      kaminari-core (= 1.2.1)
    kaminari-actionview (1.2.1)
      actionview
      kaminari-core (= 1.2.1)
    kaminari-activerecord (1.2.1)
      activerecord
      kaminari-core (= 1.2.1)
    kaminari-core (1.2.1)
    listen (3.0.8)
      rb-fsevent (~> 0.9, >= 0.9.4)
      rb-inotify (~> 0.9, >= 0.9.7)
    loofah (2.7.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    mail (2.7.1)
      mini_mime (>= 0.1.1)
    mailgun_rails (0.9.0)
      actionmailer (>= 3.2.13)
      json (>= 1.7.7)
      rest-client (>= 1.6.7)
    medium-editor-insert-plugin-rails (0.0.1)
      railties (>= 4.0)
    medium-editor-rails (2.3.1)
      railties (>= 3.0)
    meta-tags (2.13.0)
      actionpack (>= 3.2.0, < 6.1)
    method_source (1.0.0)
    mime-types (3.3.1)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2020.0512)
    mini_magick (4.10.1)
    mini_mime (1.0.2)
    mini_portile2 (2.4.0)
    minitest (5.14.2)
    multi_json (1.15.0)
    multi_xml (0.6.0)
    multipart-post (2.1.1)
    netrc (0.11.0)
    nio4r (2.5.4)
    nokogiri (1.10.10)
      mini_portile2 (~> 2.4.0)
    oauth2 (1.4.4)
      faraday (>= 0.8, < 2.0)
      jwt (>= 1.0, < 3.0)
      multi_json (~> 1.3)
      multi_xml (~> 0.5)
      rack (>= 1.2, < 3)
    omniauth (1.9.1)
      hashie (>= 3.4.6)
      rack (>= 1.6.2, < 3)
    omniauth-facebook (7.0.0)
      omniauth-oauth2 (~> 1.2)
    omniauth-google-oauth2 (0.8.0)
      jwt (>= 2.0)
      omniauth (>= 1.1.1)
      omniauth-oauth2 (>= 1.6)
    omniauth-oauth2 (1.7.0)
      oauth2 (~> 1.4)
      omniauth (~> 1.9)
    orm_adapter (0.5.0)
    pg (1.2.3)
    polyamorous (2.3.0)
      activerecord (>= 5.0)
    popper_js (1.16.0)
    public_uid (2.1.1)
      activerecord (> 4.2)
    puma (3.12.6)
    rack (2.2.3)
    rack-test (1.1.0)
      rack (>= 1.0, < 3)
    rails (5.1.7)
      actioncable (= 5.1.7)
      actionmailer (= 5.1.7)
      actionpack (= 5.1.7)
      actionview (= 5.1.7)
      activejob (= 5.1.7)
      activemodel (= 5.1.7)
      activerecord (= 5.1.7)
      activesupport (= 5.1.7)
      bundler (>= 1.3.0)
      railties (= 5.1.7)
      sprockets-rails (>= 2.0.0)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.3.0)
      loofah (~> 2.3)
    rails-i18n (5.1.3)
      i18n (>= 0.7, < 2)
      railties (>= 5.0, < 6)
    rails-ujs (0.1.0)
      railties (>= 3.1)
    railties (5.1.7)
      actionpack (= 5.1.7)
      activesupport (= 5.1.7)
      method_source
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (13.0.1)
    ransack (2.3.0)
      actionpack (>= 5.0)
      activerecord (>= 5.0)
      activesupport (>= 5.0)
      i18n
      polyamorous (= 2.3.0)
    rb-fsevent (0.10.4)
    rb-inotify (0.10.1)
      ffi (~> 1.0)
    responders (3.0.1)
      actionpack (>= 5.0)
      railties (>= 5.0)
    rest-client (2.1.0)
      http-accept (>= 1.7.0, < 2.0)
      http-cookie (>= 1.0.2, < 2.0)
      mime-types (>= 1.16, < 4.0)
      netrc (~> 0.8)
    ruby2_keywords (0.0.2)
    ruby_http_client (3.5.1)
    sass (3.7.4)
      sass-listen (~> 4.0.0)
    sass-listen (4.0.0)
      rb-fsevent (~> 0.9, >= 0.9.4)
      rb-inotify (~> 0.9, >= 0.9.7)
    sass-rails (5.0.7)
      railties (>= 4.0.0, < 6)
      sass (~> 3.1)
      sprockets (>= 2.8, < 4.0)
      sprockets-rails (>= 2.0, < 4.0)
      tilt (>= 1.1, < 3)
    sassc (2.4.0)
      ffi (~> 1.9)
    sassc-rails (2.1.2)
      railties (>= 4.0.0)
      sassc (>= 2.0)
      sprockets (> 3.0)
      sprockets-rails
      tilt
    sendgrid-ruby (6.3.4)
      ruby_http_client (~> 3.4)
    simple_form (5.0.2)
      actionpack (>= 5.0)
      activemodel (>= 5.0)
    spring (2.1.1)
    spring-watcher-listen (2.0.1)
      listen (>= 2.7, < 4.0)
      spring (>= 1.2, < 3.0)
    sprockets (3.7.2)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-es6 (0.9.2)
      babel-source (>= 5.8.11)
      babel-transpiler
      sprockets (>= 3.0.0)
    sprockets-rails (3.2.2)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    sqlite3 (1.3.13)
    thor (1.0.1)
    thread_safe (0.3.6)
    tilt (2.0.10)
    turbolinks (5.2.1)
      turbolinks-source (~> 5.2)
    turbolinks-source (5.2.0)
    tzinfo (1.2.7)
      thread_safe (~> 0.1)
    uglifier (4.2.0)
      execjs (>= 0.3.0, < 3)
    unf (0.1.4)
      unf_ext
    unf_ext (0.0.7.7)
    uniform_notifier (1.13.0)
    warden (1.2.9)
      rack (>= 2.0.9)
    web-console (3.7.0)
      actionview (>= 5.0)
      activemodel (>= 5.0)
      bindex (>= 0.4.0)
      railties (>= 5.0)
    websocket-driver (0.6.5)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)

PLATFORMS
  ruby

DEPENDENCIES
  activeadmin
  acts-as-taggable-on
  bootstrap
  brakeman
  bullet
  byebug
  carrierwave (~> 1.3.1)
  cloudinary (= 1.11.1)
  coffee-rails (~> 4.2)
  devise
  devise-i18n
  dotenv-rails
  enum_help
  friendly_id (~> 5.2.4)
  heroku-deflater
  impressionist (~> 1.6.1)
  jbuilder (~> 2.5)
  jquery-rails
  jquery-ui-rails
  listen (~> 3.0.5)
  mailgun_rails
  medium-editor-insert-plugin-rails
  medium-editor-rails
  meta-tags
  mini_magick
  omniauth
  omniauth-facebook
  omniauth-google-oauth2
  pg
  public_uid
  puma (~> 3.0)
  rails (~> 5.1.4)
  rails-i18n
  rails-ujs
  ransack
  sass-rails (~> 5.0)
  sendgrid-ruby
  simple_form
  spring
  spring-watcher-listen (~> 2.0.0)
  sqlite3 (~> 1.3.6)
  turbolinks (~> 5)
  tzinfo-data
  uglifier (>= 1.3.0)
  web-console (>= 3.3.0)

BUNDLED WITH
   2.1.4

1 件の回答 1

0

devise-i18n-viewsを削除してからbundle installを再実行してみダメでしたか?
もしかするとbundle cleanもやらないとgemが完全に消えていないかもしれませんね。

3
  • 返信いただいてありがとうございます。bundel clean をし、ターミナルからgem listで確認してみたのですが、動作は変わっておらずです。何か別の方法をご存知でありますか??
    – user41929
    2020年10月9日 9:43
  • 現在のGemfileと、Gemfile.lockの内容を書いてもらってもよいですか? Gemをすべて再インストールしてしまうという方法もあるのかもしれません。(vendorフォルダーを削除して再度bundle installする) 2020年10月15日 12:20
  • ありがとうございます。上記の質問を編集します。
    – user41929
    2020年10月19日 4:32

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。