Rails 5.0.2
で開発し、Heroku
に公開しています。
アカウント周りはdevise
を利用しています。
今ぶつかっている問題
User
が登録済みのemail
を変更する仕様を入れています。localでの開発環境(development)では問題なく変更されるのですが、本番(production)ではemail
のupdate
がされないという問題にぶつかっています。原因があるとすると、devise
だとは思っているのですが、解決策わからず、お分かりの方御指南頂けますと幸甚です。
devise
ではdatabase_authenticatable
, registerable
, recoverable
,rememberable
, trackable
, validatable
, omniauthable
, omniauth_providers => [:facebook]
, confirmable(productionのみ)
を利用しています。
Code(model, table, controller)
Ruby
1### User modelとtable 2== Schema Information 3 4Table name: users 5 6 id :integer not null, primary key 7 email_for_index :string not null 8 family_name :string 9 given_name :string 10 family_name_kana :string 11 given_name_kana :string 12 user_name :string not null 13 address :string 14 user_icon :text 15 start_date :date 16 end_date :date 17 suspended :boolean default(FALSE) 18 created_at :datetime not null 19 updated_at :datetime not null 20 email :string default(""), not null 21 encrypted_password :string default(""), not null 22 reset_password_token :string 23 reset_password_sent_at :datetime 24 remember_created_at :datetime 25 sign_in_count :integer default(0), not null 26 current_sign_in_at :datetime 27 last_sign_in_at :datetime 28 current_sign_in_ip :inet 29 last_sign_in_ip :inet 30 provider :string 31 uid :string 32 image :text 33 confirmation_token :string 34 confirmed_at :datetime 35 confirmation_sent_at :datetime 36 unconfirmed_email :string 37 failed_attempts :integer default(0), not null 38 unlock_token :string 39 locked_at :datetime 40 41 42class User < ApplicationRecord 43 devise :database_authenticatable, :registerable, 44 :recoverable, :rememberable, :trackable, :validatable, 45 :omniauthable, :omniauth_providers => [:facebook] 46 if Rails.env.production? 47 devise :confirmable 48 end 49 50 mount_uploader :user_icon, UserIconUploader 51 52 validates :user_name, presence: true, uniqueness: { case_sensitive: :true }, 53 length: { minimum: 1, maximun: 20, allow_blank: true } 54 #, format: { with: /\A[A-Za-z]\w*\z/, allow_blank: false } 55 56 before_validation do 57 self.email_for_index = email.downcase if email 58 end 59 60 def self.new_with_session(params, session) 61 super.tap do |user| 62 if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"] 63 user.email = data["email"] if user.email.blank? 64 end 65 end 66 end 67 68 def self.from_omniauth(auth) 69 where(provider: auth.provider, uid: auth.uid).first_or_create do |user| 70 user.email = auth.info.email 71 user.password = Devise.friendly_token[0,20] 72 user.given_name = auth.info.name 73 user.user_name = auth.info.name # assuming the user model has a name 74 user.image = auth.info.image # assuming the user model has an image 75 user.user_icon = user.image 76 # If you are using confirmable and the provider(s) you use validate emails, 77 # uncomment the line below to skip the confirmation emails. 78 # user.skip_confirmation! 79 end 80 end 81 82 def self.new_with_session(params, session) 83 super.tap do |user| 84 if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"] 85 user.email = data["email"] if user.email.blank? 86 end 87 end 88 end 89 90 def active? 91 !suspended? && start_date <= Date.today && (end_date.nil? || end_date > Date.today) 92 end 93end
ruby
1class User::AccountsController < User::Base 2 before_action :authenticate_user! 3 before_action :search_preparation 4 5 def show 6 @user = current_user 7 8 respond_to do |format| 9 format.html { 10 render :show 11 } 12 format.json { 13 render json: {status: true} 14 } 15 end 16 end 17 18 def edit 19 @user = current_user 20 end 21 22 def update 23 @user = current_user 24 @user.assign_attributes(user_params) 25 if @user.save 26 redirect_to :user_account, notice: "基本情報を更新しました。" 27 else 28 render "edit" 29 end 30 end 31 32 def icon_edit 33 @user = current_user 34 end 35 36 private def user_params 37 attrs = [ 38 :email_for_index, :email, :family_name, :given_name, :family_name_kana, :given_name_kana, 39 :user_name, :address, :user_icon, :remove_user_icon 40 ] 41 params.require(:user).permit(attrs) 42 end 43end 44
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。