前提・実現したいこと
前提として、カフェ情報を登録できるようなアプリを作成しました。
発生している問題としてnameやaddressを入力してから最後に"登録する"のボタンを押すとindexに
遷移するはずが失敗してしまいWe're sorry, but something went wrong.が表示されてしまいます。
heroku logs -tでエラーログの方確認したところ下記の通りでした。
Excon::Error::Forbidden (Expected(204) <=> Actual(403 Forbidden)
ちなみにローカル環境ではエラー等は出なく正常通りに機能します。
実現したいこととして、カフェ登録を正常通り成功させ、indexに遷移するようにしたいです。
どなたかご教授していただきたくよろしくお願い致します。
エラーログに関して
2021-10-09T03:43:32.588361+00:00 app[web.1]: I, [2021-10-09T03:43:32.588277 #4] INFO -- : [299fb0e3-fc18-4735-aaee-0fd60a777631] Started POST "/caves" for 221.118.208.16 at 2021-10-09 03:43:32 +0000 2021-10-09T03:43:32.589495+00:00 app[web.1]: I, [2021-10-09T03:43:32.589439 #4] INFO -- : [299fb0e3-fc18-4735-aaee-0fd60a777631] Processing by CavesController#create as HTML 2021-10-09T03:43:32.589684+00:00 app[web.1]: I, [2021-10-09T03:43:32.589637 #4] INFO -- : [299fb0e3-fc18-4735-aaee-0fd60a777631] Parameters: {"authenticity_token"=>"[FILTERED]", "cafe"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x0000562b25dbf050 @tempfile=#<Tempfile:/tmp/RackMultipart20211009-4-zcm7md.jpeg>, @original_filename="プロント JRゲートタワー店.jpeg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"cafe[image]\"; filename=\"\xE3\x83\x95\xE3\x82\x9A\xE3\x83\xAD\xE3\x83\xB3\xE3\x83\x88 JR\xE3\x82\xB1\xE3\x82\x99\xE3\x83\xBC\xE3\x83\x88\xE3\x82\xBF\xE3\x83\xAF\xE3\x83\xBC\xE5\xBA\x97.jpeg\"\r\nContent-Type: image/jpeg\r\n">, "name"=>"PRONT JRゲートタワー店", "address"=>"愛知県名古屋市中村区名駅1丁目1−3", "business_hours(1i)"=>"2021", "business_hours(2i)"=>"10", "business_hours(3i)"=>"9", "business_hours(4i)"=>"08", "business_hours(5i)"=>"00", "end_business_hours(1i)"=>"2021", "end_business_hours(2i)"=>"10", "end_business_hours(3i)"=>"9", "end_business_hours(4i)"=>"21", "end_business_hours(5i)"=>"00", "number_seats"=>"10", "wifi"=>"1"}, "commit"=>"登録する"} 2021-10-09T03:43:38.679497+00:00 app[web.1]: I, [2021-10-09T03:43:38.679406 #4] INFO -- : [299fb0e3-fc18-4735-aaee-0fd60a777631] Completed 500 Internal Server Error in 6090ms (ActiveRecord: 6.3ms | Allocations: 26015) 2021-10-09T03:43:38.680618+00:00 app[web.1]: F, [2021-10-09T03:43:38.680519 #4] FATAL -- : [299fb0e3-fc18-4735-aaee-0fd60a777631] 2021-10-09T03:43:38.680619+00:00 app[web.1]: [299fb0e3-fc18-4735-aaee-0fd60a777631] Excon::Error::Forbidden (Expected(204) <=> Actual(403 Forbidden) 2021-10-09T03:43:38.680620+00:00 app[web.1]: excon.error.response 2021-10-09T03:43:38.680629+00:00 app[web.1]: :body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>X36HRJ7SHNMD3Q5T</RequestId><HostId>4vumE3DJZ4qsuMKqqGqz6iarWDSrrfb8R6xGP9YfbtUsjdJJKTERPGZpLPXsEaJFiFZXpZ16jPs=</HostId></Error>" 2021-10-09T03:43:38.680629+00:00 app[web.1]: :cookies => [ 2021-10-09T03:43:38.680630+00:00 app[web.1]: ] 2021-10-09T03:43:38.680630+00:00 app[web.1]: :headers => { 2021-10-09T03:43:38.680631+00:00 app[web.1]: "Content-Type" => "application/xml" 2021-10-09T03:43:38.680631+00:00 app[web.1]: "Date" => "Sat, 09 Oct 2021 03:43:37 GMT" 2021-10-09T03:43:38.680632+00:00 app[web.1]: "Server" => "AmazonS3" 2021-10-09T03:43:38.680633+00:00 app[web.1]: "x-amz-id-2" => "4vumE3DJZ4qsuMKqqGqz6iarWDSrrfb8R6xGP9YfbtUsjdJJKTERPGZpLPXsEaJFiFZXpZ16jPs=" 2021-10-09T03:43:38.680633+00:00 app[web.1]: "x-amz-request-id" => "X36HRJ7SHNMD3Q5T" 2021-10-09T03:43:38.680633+00:00 app[web.1]: } 2021-10-09T03:43:38.680634+00:00 app[web.1]: :host => "searching-outlet-test.s3.ap-northeast-1.amazonaws.com" 2021-10-09T03:43:38.680634+00:00 app[web.1]: :local_address => "172.18.225.54" 2021-10-09T03:43:38.680635+00:00 app[web.1]: :local_port => 35540 2021-10-09T03:43:38.680637+00:00 app[web.1]: :path => "/uploads/tmp/1633751012-17817099207315-0001-8821/%E3%83%95%E3%82%9A%E3%83%AD%E3%83%B3%E3%83%88_JR%E3%82%B1%E3%82%99%E3%83%BC%E3%83%88%E3%82%BF%E3%83%AF%E3%83%BC%E5%BA%97.jpeg" 2021-10-09T03:43:38.680637+00:00 app[web.1]: :port => 443 2021-10-09T03:43:38.680637+00:00 app[web.1]: :reason_phrase => "Forbidden" 2021-10-09T03:43:38.680637+00:00 app[web.1]: :remote_ip => "52.219.4.119" 2021-10-09T03:43:38.680638+00:00 app[web.1]: :status => 403 2021-10-09T03:43:38.680638+00:00 app[web.1]: :status_line => "HTTP/1.1 403 Forbidden\r\n" 2021-10-09T03:43:38.680638+00:00 app[web.1]: ): 2021-10-09T03:43:38.680639+00:00 app[web.1]: [299fb0e3-fc18-4735-aaee-0fd60a777631] 2021-10-09T03:43:38.680639+00:00 app[web.1]: [299fb0e3-fc18-4735-aaee-0fd60a777631] app/controllers/caves_controller.rb:27:in `block in create' 2021-10-09T03:43:38.680639+00:00 app[web.1]: [299fb0e3-fc18-4735-aaee-0fd60a777631] app/controllers/caves_controller.rb:26:in `create' 2021-10-09T03:43:38.686334+00:00 heroku[router]: at=info method=POST path="/caves" host=vast-everglades-74020.herokuapp.com request_id=299fb0e3-fc18-4735-aaee-0fd60a777631 fwd="221.118.208.16" dyno=web.1 connect=0ms service=6828ms status=500 bytes=1827 protocol=https
該当のソースコード
carrierwave
1unless Rails.env.development? || Rails.env.test? 2 CarrierWave.configure do |config| 3 config.storage :fog 4 config.fog_provider = 'fog/aws' 5 config.fog_directory = 'searching-outlet-test' 6 config.fog_public = false 7 config.fog_credentials = { 8 provider: 'AWS', 9 aws_access_key_id: '', 10 aws_secret_access_key: '', 11 region: 'ap-northeast-1' 12 } 13 end 14end
uploader
1class ImageUploader < CarrierWave::Uploader::Base 2 # Include RMagick or MiniMagick support: 3 include CarrierWave::RMagick 4 # include CarrierWave::MiniMagick 5 6 # Choose what kind of storage to use for this uploader: 7 # storage :file 8 # storage :fog 9 if Rails.env.development? 10 storage :file 11 elsif Rails.env.test? 12 storage :file 13 else 14 storage :fog 15 end 16 # Override the directory where uploaded files will be stored. 17 # This is a sensible default for uploaders that are meant to be mounted: 18 def store_dir 19 "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 20 end 21 22 # Provide a default URL as a default if there hasn't been a file uploaded: 23 # def default_url(*args) 24 # # For Rails 3.1+ asset pipeline compatibility: 25 # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) 26 # 27 # "/images/fallback/" + [version_name, "default.png"].compact.join('_') 28 # end 29 30 # Process files as they are uploaded: 31 # process scale: [200, 300] 32 process :resize_to_limit => [700, 700] 33 process :convert => 'jpg' 34 # 35 # def scale(width, height) 36 # # do something 37 # end 38 39 # Create different versions of your uploaded files: 40 version :thumb do 41 process :resize_to_limit => [300, 300] 42 end 43 44 # Add an allowlist of extensions which are allowed to be uploaded. 45 # For images you might use something like this: 46 def extension_allowlist 47 %w(jpg jpeg gif png) 48 end 49 50 # Override the filename of the uploaded files: 51 # Avoid using model.id or version_name here, see uploader/store.rb for details. 52 def filename 53 super.chomp(File.extname(super)) + '.jpg' 54 if original_filename.present? 55 time = Time.now 56 name = time.strftime('%Y%m%d%H%M%S') + '.jpg' 57 name.downcase 58 end 59 end 60end
storage
1test: 2 service: Disk 3 root: <%= Rails.root.join("tmp/storage") %> 4 5local: 6 service: Disk 7 root: <%= Rails.root.join("storage") %> 8 9# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10amazon: 11 service: S3 12 access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %> 13 secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %> 14 region: ap-northeast-1 15 bucket: searching-outlet-test 16 17# Remember not to checkin your GCS keyfile to a repository 18# google: 19# service: GCS 20# project: your_project 21# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22# bucket: your_own_bucket 23 24# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25# microsoft: 26# service: AzureStorage 27# storage_account_name: your_account_name 28# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29# container: your_container_name 30 31# mirror: 32# service: Mirror 33# primary: local 34# mirrors: [ amazon, google, microsoft ]
試したこと
エラーログから考えるとs3との連携がうまくできていないということがわかり色々と記事を探すと
carrierwaveの設定を見直している記事を多く発見し自分のものも確認してみましたが、
バケット名も特に問題がなく修正箇所がないように思えました。
また、We're sorry, but something went wrong.のエラーの解決の記事もいくつか確認して
みたところ、heroku run rails db:migrateでの解決策が多く見受けられたので実践してみたところ
ローカルでのactive storageに内容がmigrateされていなかったようでmigrateされていましたが
解決はされませんでした。
access deneyedとありバケットポリシーの設定をしていなかったので設定しましたが
これでも解決には至りませんでした。
補足情報(FW/ツールのバージョンなど)
docker/docker-compose
rails/ruby
circle ci cd
回答1件
あなたの回答
tips
プレビュー