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

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

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

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

Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Q&A

1回答

899閲覧

deviseでマイページ編集機能を実装したが、Herokuで正常に動作しない。

kwtkwt

総合スコア21

Ruby on Rails 5

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

Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

0グッド

0クリップ

投稿2021/08/20 06:47

編集2021/08/20 06:50

前提・実現したいこと

deviseを使ってユーザーのマイページ編集機能を実装しました。
プロフィールを入力して保存し、マイページから確認できるようになっています。
ローカルでは正常に動作していますが、Heroku上ではマイページをUpdateしてもデータが反映されません。

(環境)
・ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
・Rails 5.1.6

発生している問題・エラーメッセージ

特にありません。

該当のソースコード

app/controllers/user_devises/registrations_controller.rb

ruby

1# frozen_string_literal: true 2 3class UserDevises::RegistrationsController < Devise::RegistrationsController 4 # before_action :configure_sign_up_params, only: [:create] 5 # before_action :configure_account_update_params, only: [:update] 6 7 # GET /resource/sign_up 8 # def new 9 # super 10 # end 11 12 # POST /resource 13 # def create 14 # super 15 # end 16 17 # GET /resource/edit 18 # def edit 19 # super 20 # end 21 22 # PUT /resource 23 # def update 24 # super 25 # end 26 27 # DELETE /resource 28 # def destroy 29 # super 30 # end 31 32 # GET /resource/cancel 33 # Forces the session data which is usually expired after sign 34 # in to be expired now. This is useful if the user wants to 35 # cancel oauth signing in/up in the middle of the process, 36 # removing all OAuth session data. 37 # def cancel 38 # super 39 # end 40 41 # protected 42 43 # If you have extra params to permit, append them to the sanitizer. 44 # def configure_sign_up_params 45 # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) 46 # end 47 48 # If you have extra params to permit, append them to the sanitizer. 49 # def configure_account_update_params 50 # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) 51 # end 52 53 #アカウント登録後のリダイレクト先 54 def after_sign_up_path_for(resource) 55 56 end 57 58 #アカウント情報、プロフィール編集後のリダイレクト先 59 def after_update_path_for(resource) 60 # マイページへ遷移 61 user_devise_path(resource.id) 62 end 63 64 # The path used after sign up for inactive accounts. 65 # def after_inactive_sign_up_path_for(resource) 66 # super(resource) 67 # end 68end 69

app/views/devise/registrations/edit.html.erb

erb

1<div class="p-edit"> 2 <% if t('.title', resource: resource.model_name.human) == "User devise編集" %> 3 <% @name = params[:name] %> 4 5 <% if @name == "アカウント情報変更" %> 6 <h2 class="c-heading__h2--bold u-mb20">アカウント情報変更</h2> 7 8 <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> 9 <%= render "devise/shared/error_messages", resource: resource %> 10 11 <div class="p-edit__field"> 12 <%= f.label :メールアドレス %> 13 <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 14 </div> 15 16 <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> 17 <div><%= t('.currently_waiting_confirmation_for_email', email: resource.unconfirmed_email) %></div> 18 <% end %> 19 20 <div class="p-edit__field"> 21 <%= f.label :現在のパスワード %> 22 <%= f.password_field :current_password, autocomplete: "current-password" %> 23 </div> 24 25 <div class="p-edit__field"> 26 <%= f.label :新しいパスワード %> 27 <% if @minimum_password_length %> 28 <p><%= t('devise.shared.minimum_password_length', count: @minimum_password_length) %></p> 29 <% end %> 30 <%= f.password_field :password, autocomplete: "new-password" %> 31 </div> 32 33 <div class="p-edit__field"> 34 <%= f.label :新しいパスワード【確認】 %> 35 <%= f.password_field :password_confirmation, autocomplete: "new-password" %> 36 </div> 37 38 39 <div class="p-edit__actions"> 40 <%= f.submit t('.update'), class: "c-btn__change" %> 41 </div> 42 <% end %> 43 44 45 46 47 <% elsif @name == "プロフィール変更" %> 48 49 <h2 class="c-heading__h2--bold u-mb20">プロフィール変更</h2> 50 51 <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> 52 <%= render "devise/shared/error_messages", resource: resource %> 53 54 55 <%# ここまでの情報がないと、編集内容がなぜか反映されない  %> 56 <div class="p-edit__field" style="display: none;"> 57 <%= f.label :メールアドレス %> 58 <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 59 </div> 60 61 <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> 62 <div style="display: none;"><%= t('.currently_waiting_confirmation_for_email', email: resource.unconfirmed_email) %></div> 63 <% end %> 64 65 <div class="p-edit__field" style="display: none;"> 66 <%= f.label :現在のパスワード %> 67 <%= f.password_field :current_password, autocomplete: "current-password" %> 68 </div> 69 70 <div class="p-edit__field" style="display: none;"> 71 <%= f.label :新しいパスワード %> 72 <% if @minimum_password_length %> 73 <p><%= t('devise.shared.minimum_password_length', count: @minimum_password_length) %></p> 74 <% end %> 75 <%= f.password_field :password, autocomplete: "new-password" %> 76 </div> 77 78 <div class="p-edit__field" style="display: none;"> 79 <%= f.label :新しいパスワード【確認】 %> 80 <%= f.password_field :password_confirmation, autocomplete: "new-password" %> 81 </div> 82 <%# ここまでの情報がないと、編集内容がなぜか反映されない  %> 83 84 <div class="p-edit__field"> 85 <%= f.label :氏名 %> 86 <%= f.text_field :name, autofocus: true, autocomplete: "name" %> 87 </div> 88 89 <div class="p-edit__field"> 90 <%= f.label :ふりがな %> 91 <%= f.text_field :furigane, autofocus: true, autocomplete: "furigane" %> 92 </div> 93 94 <div class="p-edit__field"> 95 <%= f.label :生年月日 %> 96 <%= f.text_field :birthday, autofocus: true, autocomplete: "birthday" %> 97 </div> 98 99 <div class="p-edit__field"> 100 <%= f.label :性別 %> 101 <%= f.text_field :sex, autofocus: true, autocomplete: "sex" %> 102 </div> 103 104 <div class="p-edit__field"> 105 <%= f.label :現在の職業 %> 106 <%= f.text_field :profession, autofocus: true, autocomplete: "profession" %> 107 </div> 108 109 <div class="p-edit__field"> 110 <%= f.label :直近の職務経歴 %> 111 <%= f.text_area :career, autofocus: true, autocomplete: "career" %> 112 </div> 113 114 <div class="p-edit__field"> 115 <%= f.label :電話番号 %> 116 <%= f.text_field :number, autofocus: true, autocomplete: "number" %> 117 </div> 118 119 <div class="p-edit__field"> 120 <%= f.label :住所 %> 121 <%= f.text_field :address, autofocus: true, autocomplete: "address" %> 122 </div> 123 124 <div class="p-edit__field"> 125 <%= f.label :備考・PR %> 126 <%= f.text_area :pr, autofocus: true, autocomplete: "pr" %> 127 </div> 128 129 <div class="p-edit__actions"> 130 <%= f.submit t('.update'), class: "c-btn__change" %> 131 </div> 132 <% end %> 133 <% end %> 134 135 136 137 138 <h3><%= t('.cancel_my_account') %></h3> 139 140 <p><%= t('.unhappy') %> <%= button_to t('.cancel_my_account'), registration_path(resource_name), data: { confirm: t('.are_you_sure') }, method: :delete %></p> 141 142 <%= link_to t('devise.shared.links.back'), :back %> 143 144 145 <% else %> 146 147 <h2>会社情報変更</h2> 148 149 <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> 150 <%= render "devise/shared/error_messages", resource: resource %> 151 152 <div class="field"> 153 <%= f.label :email %><br /> 154 <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 155 </div> 156 157 158 <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> 159 <div><%= t('.currently_waiting_confirmation_for_email', email: resource.unconfirmed_email) %></div> 160 <% end %> 161 162 <div class="field"> 163 <%= f.label :password %> <i>(<%= t('.leave_blank_if_you_don_t_want_to_change_it') %>)</i><br /> 164 <%= f.password_field :password, autocomplete: "new-password" %> 165 <% if @minimum_password_length %> 166 <br /> 167 <em><%= t('devise.shared.minimum_password_length', count: @minimum_password_length) %></em> 168 <% end %> 169 </div> 170 171 <div class="field"> 172 <%= f.label :password_confirmation %><br /> 173 <%= f.password_field :password_confirmation, autocomplete: "new-password" %> 174 </div> 175 176 <div class="field"> 177 <%= f.label :current_password %> <i>(<%= t('.we_need_your_current_password_to_confirm_your_changes') %>)</i><br /> 178 <%= f.password_field :current_password, autocomplete: "current-password" %> 179 </div> 180 181 <div class="actions"> 182 <%= f.submit t('.update') %> 183 </div> 184 <% end %> 185 186 <h3><%= t('.cancel_my_account') %></h3> 187 188 <p><%= t('.unhappy') %> <%= button_to t('.cancel_my_account'), registration_path(resource_name), data: { confirm: t('.are_you_sure') }, method: :delete %></p> 189 190 <%= link_to t('devise.shared.links.back'), :back %> 191 192 <% end %> 193</div> 194 195 196 197

試したこと

https://qiita.com/yusuke1209kitamura/items/dcaf3622c21cf08ebdba

https://teratail.com/questions/253843

こちらを試したみましたが、解決せず...

試しに、name属性を更新して、ログを見てみると、ローカルでは正常に更新されていて、herokuでは更新されていないようです...

よろしくお願いいたします。

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

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

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

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

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

guest

回答1

0

ログ

ローカル

Processing by UserDevises::RegistrationsController#update as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"2YK2Y3fS2j3BTNmpKTSw3yyWOyqYoyWnOckCWe+8F8qJc1sGL04U6alOPaKskUBt/83f8MbFkffD260iwXGvvw==", "user_devise"=>{"email"=>"aaa@gmail.com", "current_password"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "name"=>"ssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "furigane"=>"", "birthday"=>"", "sex"=>"", "profession"=>"", "career"=>"", "number"=>"", "address"=>"", "pr"=>""}, "commit"=>"更新"} UserDevise Load (0.3ms) SELECT "user_devises".* FROM "user_devises" WHERE "user_devises"."id" = ? ORDER BY "user_devises"."id" ASC LIMIT ? [["id", 5], ["LIMIT", 1]] UserDevise Load (0.3ms) SELECT "user_devises".* FROM "user_devises" WHERE "user_devises"."id" = ? LIMIT ? [["id", 5], ["LIMIT", 1]] (0.2ms) begin transaction SQL (0.6ms) UPDATE "user_devises" SET "name" = ?, "updated_at" = ? WHERE "user_devises"."id" = ? [["name", "ssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], ["updated_at", "2021-08-20 05:31:45.754343"], ["id", 5]] (2.0ms) commit transaction Redirected to http://localhost:3000/user_devises/5 Completed 302 Found in 399ms (ActiveRecord: 3.4ms)

heroku

2021-08-20T05:52:59.169415+00:00 app[web.1]: I, [2021-08-20T05:52:59.169222 #13] INFO -- : [0aefeccf-97a8-4bd8-9bae-4d9349368f4b] Processing by UserDevises::RegistrationsController#update as HTML 2021-08-20T05:52:59.169418+00:00 app[web.1]: I, [2021-08-20T05:52:59.169319 #13] INFO -- : [0aefeccf-97a8-4bd8-9bae-4d9349368f4b] Parameters: {"utf8"=>"✓", "authenticity_token"=>"AiYakWxtrNrpkFD4A9gdIqRtDR+D2zEQEUm/dQ/1qpEOTQzrHBfqTbvNhhI+GcVWu8adjVOYRFEzAbg7DXKfwQ==", "user_devise"=>{"email"=>"aaa@gmail.com", "current_password"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "name"=>"", "furigane"=>"lo", "birthday"=>"", "sex"=>"", "profession"=>"", "career"=>"", "number"=>"", "address"=>"", "pr"=>"kkk"}, "commit"=>"更新"} 2021-08-20T05:52:59.173944+00:00 app[web.1]: D, [2021-08-20T05:52:59.173870 #13] DEBUG -- : [0aefeccf-97a8-4bd8-9bae-4d9349368f4b] UserDevise Load (1.3ms) SELECT "user_devises".* FROM "user_devises" WHERE "user_devises"."id" = $1 ORDER BY "user_devises"."id" ASC LIMIT $2 [["id", 7], ["LIMIT", 1]] 2021-08-20T05:52:59.176414+00:00 app[web.1]: D, [2021-08-20T05:52:59.176330 #13] DEBUG -- : [0aefeccf-97a8-4bd8-9bae-4d9349368f4b] UserDevise Load (1.2ms) SELECT "user_devises".* FROM "user_devises" WHERE "user_devises"."id" = $1 LIMIT $2 [["id", 7], ["LIMIT", 1]]

よろしくお願いいたします。

投稿2021/08/20 06:48

kwtkwt

総合スコア21

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問