いつもお世話になっております。
下記の複雑な値(4つ目の貼り付けておりますデバックの内容を参照ください)の中から、
image_path: "bdc33375-ce69-4b6d-a561-5dedcb2a79b8.png"
を取り出しビューに反映させたいのですが、どのように取り出せばよろしいでしょうか。
いろいろとターミナルと向き合ったのですが、CarrierWaveで画像を取り込んでいるためなのか、
簡単に取り出せずに苦戦しております。
下記に貼り付ける デバックの内容 に取り出したい値がございます。
必要かはわかりませんが、コントローラー、モデル、ビューのコードも貼り付けいたします。
どうぞよろしくお願い申し上げます。
コントローラー
def user_products_index @products = @user.products.includes(:images) end
対応するview
.product-show-box .product-show-box_img = image_tag product.images[0].image_path ←値が取り出せずに苦戦している箇所です。デバックの結果は下記 .product-show-box_text .product-show-box_text_title %p #{product.name} .product-show-box_text_introduction %p #{product.introduction}
デバックの内容
[5] pry(#<#<Class:0x00007fe724a0cbf8>>)> product.images[0].image_path => #<ImageUploader:0x00007fe728036530 @cache_id=nil, @file= #<CarrierWave::SanitizedFile:0x00007fe728035ec8 @content=nil, @content_type=nil, @file="/public/uploads/image/image_path/1/bdc33375-ce69-4b6d-a561-5dedcb2a79b8.png", @original_filename=nil>, @filename=nil, @format=nil, @model= #<Image:0x00007fe7240b91c8 id: 1, image_path: "bdc33375-ce69-4b6d-a561-5dedcb2a79b8.png", ←これを取り出したい product_id: 1, created_at: Wed, 17 Apr 2019 09:26:01 UTC +00:00, updated_at: Wed, 17 Apr 2019 09:26:01 UTC +00:00>, @mounted_as=:image_path, @storage=#<CarrierWave::Storage::File:0x00007fe7280363a0 @cache_called=nil, @uploader=#<ImageUploader:0x00007fe728036530 ...>>, @versions={}>
Userモデル
class User < ApplicationRecord has_many :products, dependent: :destroy has_many :messages, dependent: :destroy end
Productモデル
class Product < ApplicationRecord belongs_to :user has_many :images, dependent: :destroy end
Imageモデル
class Image < ApplicationRecord belongs_to :product mount_uploader :image_path, ImageUploader end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。