前提・実現したいこと
devise でマイページ編集機能を作成したが、ローカルでは更新されるが、heroku でのみ更新されません。
heroku でも更新ができるようにしたい。
仮説
ローカルとHerokuでデータベースの種類が違うからでしょうか...
ローカルでは sqlite3、Heroku では PostgreSQL を使用しています。
コード
ruby
1source 'https://rubygems.org' 2 3gem 'rails', '5.1.6' 4gem 'puma', '3.9.1' 5gem 'sass-rails', '5.0.6' 6gem 'uglifier', '3.2.0' 7gem 'coffee-rails', '4.2.2' 8gem 'jquery-rails', '4.3.1' 9gem 'turbolinks', '5.0.1' 10gem 'jbuilder', '2.7.0' 11gem 'nokogiri' 12gem 'mechanize' 13# 画像アップ 14gem 'carrierwave' 15 16gem 'rails-i18n', '~> 5.1' 17gem 'devise' 18gem 'devise-i18n' 19gem 'devise-i18n-views' 20 21# 検索機能 22gem 'ransack' 23 24# ページネーション 25gem 'kaminari' 26 27# PV数計測 28gem 'impressionist', '~>1.6.1' 29 30gem 'bootstrap' 31 32gem 'bcrypt', '3.1.12' 33 34group :development, :test do 35 gem 'sqlite3', '1.3.13' 36 gem 'byebug', '9.0.6', platform: :mri 37end 38 39group :development do 40 gem 'web-console', '3.5.1' 41 gem 'listen', '3.1.5' 42 gem 'spring', '2.0.2' 43 gem 'spring-watcher-listen', '2.0.1' 44end 45 46group :test do 47 gem 'rails-controller-testing', '1.0.2' 48 gem 'minitest', '5.10.3' 49 gem 'minitest-reporters', '1.1.14' 50 gem 'guard', '2.16.2' 51 gem 'guard-minitest', '2.4.4' 52end 53 54group :production do 55 gem 'pg', '0.20.0' 56end 57
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
app/controllers/application_controller.rb
ruby
1class ApplicationController < ActionController::Base 2 protect_from_forgery with: :exception 3 include SessionsHelper 4 5 # ログイン後に遷移するページ 6 def after_sign_in_path_for(resource) 7 mypage_companies_path(resource) 8 end 9 10 def after_sign_in_path_for(resource) 11 case resource 12 13 when Company 14 mypage_companies_path(resource) 15 16 when UserDevise 17 mypage_user_devises_path(resource) 18 end 19 end 20 21 22 23 24 # deviseコントローラーにストロングパラメータを追加する 25 before_action :configure_permitted_parameters, if: :devise_controller? 26 27 protected 28 def configure_permitted_parameters 29 # サインアップ時にnameのストロングパラメータを追加 30 # devise_parameter_sanitizer.permit(:sign_up, keys: [:name, :furigane]) 31 32 33 # アカウント編集の時にnameとprofileのストロングパラメータを追加 34 devise_parameter_sanitizer.permit(:account_update, keys: [:name, :furigane, :birthday, :sex, :profession, :career, :number, :address, :pr]) 35 end 36end
app/controllers/user_devises_controller.rb
ruby
1class UserDevisesController < ApplicationController 2 def show 3 @user_devise = UserDevise.find(params[:id]) 4 @jobs = Apply.where(user_id: current_user_devise.id) 5 end 6end 7 8
発生している問題・エラーメッセージ・ログ
ローカル
Started PUT "/user_devises" for 127.0.0.1 at 2021-09-29 13:05:38 +0900 Processing by UserDevises::RegistrationsController#update as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"IgQ/mQGRhPjXa0j2KiPL8E049P2UannNI7B3YTVmV6WDhgnXcG5J4jXOnIMLU/kfEdNlZ0HruahBc0gnZ56IEQ==", "user_devise"=>{"email"=>"aaa@gmail.com", "current_password"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "name"=>"氏名", "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.1ms) begin transaction (0.1ms) commit transaction Redirected to http://localhost:3000/user_devises/5 Completed 302 Found in 268ms (ActiveRecord: 0.7ms) Started GET "/user_devises/5" for 127.0.0.1 at 2021-09-29 13:05:38 +0900 Processing by UserDevisesController#show as HTML Parameters: {"id"=>"5"} UserDevise Load (0.2ms) SELECT "user_devises".* FROM "user_devises" WHERE "user_devises"."id" = ? LIMIT ? [["id", 5], ["LIMIT", 1]] UserDevise Load (0.4ms) SELECT "user_devises".* FROM "user_devises" WHERE "user_devises"."id" = ? ORDER BY "user_devises"."id" ASC LIMIT ? [["id", 5], ["LIMIT", 1]] Rendering user_devises/show.html.erb within layouts/application Apply Load (0.3ms) SELECT "applies".* FROM "applies" WHERE "applies"."user_id" = ? [["user_id", 5]] Rendered user_devises/show.html.erb within layouts/application (3.2ms) Rendered shared/_header.html.erb (0.8ms) Rendered shared/_footer.html.erb (0.4ms) Completed 200 OK in 92ms (Views: 86.8ms | ActiveRecord: 0.9ms)
heroku
2021-09-29T04:02:58.344402+00:00 app[web.1]: I, [2021-09-29T04:02:58.344324 #13] INFO -- : [7b81d83d-056d-48ab-82a2-8e1908d5bc83] Started PUT "/user_devises" for 60.66.62.161 at 2021-09-29 04:02:58 +0000 2021-09-29T04:02:58.345121+00:00 app[web.1]: I, [2021-09-29T04:02:58.345074 #13] INFO -- : [7b81d83d-056d-48ab-82a2-8e1908d5bc83] Processing by UserDevises::RegistrationsController#update as HTML 2021-09-29T04:02:58.345193+00:00 app[web.1]: I, [2021-09-29T04:02:58.345162 #13] INFO -- : [7b81d83d-056d-48ab-82a2-8e1908d5bc83] Parameters: {"utf8"=>"✓", "authenticity_token"=>"W/sUWu+B9Cdsi4PSMWoSIMNjOwQc7KHvp6tUBJIpSRpMYCGrno+m+9oWmB2QwNKJeuu4ErNo4zOEWt61r68vOw==", "user_devise"=>{"email"=>"aaa@yahoo.co.jp", "current_password"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "name"=>"氏名", "furigane"=>"", "birthday"=>"", "sex"=>"", "profession"=>"", "career"=>"", "number"=>"", "address"=>"", "pr"=>""}, "commit"=>"更新"} 2021-09-29T04:02:58.347617+00:00 app[web.1]: D, [2021-09-29T04:02:58.347565 #13] DEBUG -- : [7b81d83d-056d-48ab-82a2-8e1908d5bc83] UserDevise Load (0.8ms) SELECT "user_devises".* FROM "user_devises" WHERE "user_devises"."id" = $1 ORDER BY "user_devises"."id" ASC LIMIT $2 [["id", 6], ["LIMIT", 1]] 2021-09-29T04:02:58.349154+00:00 app[web.1]: D, [2021-09-29T04:02:58.349105 #13] DEBUG -- : [7b81d83d-056d-48ab-82a2-8e1908d5bc83] UserDevise Load (0.7ms) SELECT "user_devises".* FROM "user_devises" WHERE "user_devises"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]] 2021-09-29T04:02:58.612590+00:00 heroku[router]: at=info method=POST path="/user_devises" host=job-offer-rkrk.herokuapp.com request_id=7b81d83d-056d-48ab-82a2-8e1908d5bc83 fwd="60.66.62.161" dyno=web.1 connect=0ms service=272ms status=200 bytes=3425 protocol=https 2021-09-29T04:02:58.609016+00:00 app[web.1]: I, [2021-09-29T04:02:58.608857 #13] INFO -- : [7b81d83d-056d-48ab-82a2-8e1908d5bc83] Rendering devise/registrations/edit.html.erb within layouts/application 2021-09-29T04:02:58.609943+00:00 app[web.1]: I, [2021-09-29T04:02:58.609894 #13] INFO -- : [7b81d83d-056d-48ab-82a2-8e1908d5bc83] Rendered devise/registrations/edit.html.erb within layouts/application (0.9ms) 2021-09-29T04:02:58.610711+00:00 app[web.1]: I, [2021-09-29T04:02:58.610649 #13] INFO -- : [7b81d83d-056d-48ab-82a2-8e1908d5bc83] Rendered shared/_header.html.erb (0.2ms) 2021-09-29T04:02:58.610867+00:00 app[web.1]: I, [2021-09-29T04:02:58.610837 #13] INFO -- : [7b81d83d-056d-48ab-82a2-8e1908d5bc83] Rendered shared/_footer.html.erb (0.0ms) 2021-09-29T04:02:58.611024+00:00 app[web.1]: I, [2021-09-29T04:02:58.610996 #13] INFO -- : [7b81d83d-056d-48ab-82a2-8e1908d5bc83] Completed 200 OK in 266ms (Views: 2.3ms | ActiveRecord: 1.5ms)
ログを見比べてみると、herokuでのみupdateが実行されていないことが、わかります。
試したこと
heroku の再起動、
bundle install の実行
補足情報(FW/ツールのバージョンなど)
Rails 5.1.6
heroku/7.59.0 darwin-x64 node-v12.21.0
どなたかご教授いただけますでしょうか...
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。