質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
RubyGems

RubyGemsはRubyによるプログラミングのためのパッケージマネジメントツールです。ユーザはこれを使用することで、Rubyライブラリのダウンロードやアップデートや、依存関係の自動解決が可能になります。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

Q&A

解決済

1回答

2464閲覧

開発環境で変更できるemailが本番では変更できない

innjera

総合スコア132

RubyGems

RubyGemsはRubyによるプログラミングのためのパッケージマネジメントツールです。ユーザはこれを使用することで、Rubyライブラリのダウンロードやアップデートや、依存関係の自動解決が可能になります。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

0グッド

0クリップ

投稿2017/06/28 03:29

Rails 5.0.2で開発し、Herokuに公開しています。

アカウント周りはdeviseを利用しています。
今ぶつかっている問題

Userが登録済みのemailを変更する仕様を入れています。localでの開発環境(development)では問題なく変更されるのですが、本番(production)ではemailupdateがされないという問題にぶつかっています。原因があるとすると、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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

config/initializers/devise.rbconfig.reconfirmable = trueconfig.reconfirmable = falseにしたら解決しました。

投稿2017/06/28 03:39

innjera

総合スコア132

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問