###前提・実現したいこと
現在、localで作ったアプリをデプロイしようと、herokuを使いました。
その際、画像保存として使ったs3とcarrierwaveの連携させました。
dev環境や他のモデルだと問題ないのですが、あるモデルだけ、本番環境では
きちんとurlを返してくれません。
###発生している問題・エラーメッセージ
s3には無事保存できていることが確認できています。しかし、
例えば、3f984e6d-50c9-4478-9c17-93c1ae3394c3.pngという名前の画像でも
ブラウザ上では
/image/4/3" alt="3"
という風に頭の数字しか読み込もうとしてくれません。
developmentでのデータ型はstringなのですが、
productionのpgのDBではデータ型がintegerになっているのでしょうか?
( schema.rbでは t.string "image" となっています )
###該当のソースコード
<問題のモデル> class Article < ActiveRecord::Base belongs_to :user belongs_to :admin has_many :comments has_many :joins, dependent: :destroy has_many :joining_users, through: :joins, source: :user has_many :article_photos accepts_nested_attributes_for :article_photos, allow_destroy: true mount_uploader :image, PhotoUploader is_impressionable before_save do self.wanted_skill.gsub!(/[\[\]\"]/, "") if attribute_present?("wanted_skill",) self.wanted_jobkind.gsub!(/[\[\]\"]/, "") if attribute_present?("wanted_jobkind") end end <uploader> # encoding: utf-8 class PhotoUploader < CarrierWave::Uploader::Base # Include RMagick or MiniMagick support: include CarrierWave::RMagick # include CarrierWave::MiniMagick # 画像の上限を700pxにする process :resize_to_limit => [700, 700] # 保存形式をJPGにする process :convert => 'jpg' # サムネイルを生成する設定 version :thumb do process :resize_to_fit => [150, 150] end # jpg,jpeg,gif,pngしか受け付けない def extension_white_list %w(jpg jpeg gif png) end def filename "#{secure_token}.png" if original_filename.present? end def default_url 'no_photo.png' end protected def secure_token var = :"@#{mounted_as}_secure_token" model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.uuid) end # Choose what kind of storage to use for this uploader: storage :fog # Override the directory where uploaded files will be stored. # This is a sensible default for uploaders that are meant to be mounted: if Rails.env.development? def store_dir "uploads/dev/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end end if Rails.env.production? def store_dir "uploads/pro/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end end end <carrierwave.rb> CarrierWave.configure do |config| config.fog_credentials = { :provider => 'AWS', :aws_access_key_id => 'aws_access_key_id ', :aws_secret_access_key => 'aws_secret_access_key', :region => 'ap-northeast-1', # Tokyo :path_style => true } config.fog_public = true # public-read config.fog_attributes = {'Cache-Control' => 'public, max-age=86400'} config.cache_storage = :fog #キャッシュの場所をS3に変更 # テストとかで同じとこにUPLOADされたくないのでバケットを分けます config.fog_directory = 'musubino-s3' if Rails.env.production? config.fog_directory = 'musubino-s3' if Rails.env.development? CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/ end <view> <!-- 問題の部分 --> <div class="top-img-wrapper"> <%= image_tag @article.image.url %> </div>
###試したこと
別のuploaderを使いましたがうまくいきませんでした。
###お願い
railsを始めたばかりで、初めてのデプロイです。
お力を貸してもらえれば幸いです!!
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。