37
38

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Devise - email更新時に確認メールを送る(reconfirmable)

Last updated at Posted at 2015-08-09

#必要事項(4点)

##confirmableモジュールがセットされていること

/app/models/user.rb

class User < ActiveRecord::Base
  #...
  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable
  #...

##reconfirmableが有効になっていること

/config/initializers/devise.rb
Devise.setup do |config|
  #...
  config.reconfirmable = true
  #...

##データベースにunconfirmed_emailコラムが存在すること

# == Schema Information
#
# Table name: users
#
#  id                     :integer          not null, primary key
#  email                  :string           default(""), not null
#  encrypted_password     :string           default(""), not null
#  reset_password_token   :string
#  reset_password_sent_at :datetime
#  remember_created_at    :datetime
#  sign_in_count          :integer          default(0), not null
#  current_sign_in_at     :datetime
#  last_sign_in_at        :datetime
#  current_sign_in_ip     :inet
#  last_sign_in_ip        :inet
#  created_at             :datetime
#  updated_at             :datetime
#  confirmation_token     :string
#  confirmed_at           :datetime
#  confirmation_sent_at   :datetime
#  admin                  :boolean          default(FALSE)
#  username               :string
#  provider               :string
#  uid                    :string
#  unconfirmed_email      :string
#

##ユーザーに現在メール確認待ちの状態であることを知らせること

- if devise_mapping.confirmable? && resource.pending_reconfirmation?
  .alert.alert-warning
    Currently waiting confirmation for: #{resource.unconfirmed_email}

Screenshot 2015-08-09 18.07.17.png

#特定の状況でのみreconfirmable無効にしたい場合

#...
def update
 @user = User.find(params[:id])
 @user.skip_reconfirmation!
 if @user.update_attributes(params[:user])
  flash[:notice] = "User was successfully updated."
  redirect_to edit_admin_user_path(@user)
 else
  render :edit
 end
end
#...

#資料

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?