0
私の設定はすべて私のデータをリストアップする正しい方法を見つけるのが難しいです。 @product.pic_url
は5枚の画像を返しますが、最初の画像しか表示しません。APIの値をループごとに
product.rb
class TaobaoProduct
attr_reader :desc,
:approve_status,
:title,
:item_url,
:nick,
:num_iid,
:pict_url,
:pic_url,
:title,
:volume,
:zk_final_price,
:reserve_price,
:price,
:detail_url,
:cid
attr_writer :title
def initialize(product)
product.each { |name, value| instance_variable_set("@#{name}", value) }
end
# function to get individual taobao product
# product_id: Taobao product id
def self.find(product_id)
tb_hash = OpenTaobao.get(
:method => 'taobao.item.get',
:fields => 'num_iid,title,nick,desc,pic_url',
:num_iid => product_id
)
new(tb_hash["item_get_response"]["item"])
end
end
product.haml
.container
.row
.col-xs-12
%h1= @product.title
.row
.product-v2.col-md-9
.row
.col-md-6.col-xs-12
%img{:src => "#{@product.pic_url}" + "_400x400.jpg"}
.col-md-6.col-xs-12
.price-v2
これは実際には私は先に試しましたが、このエラーが '#String:0x007f71583350d8>のための未定義メソッド – NooBskie
に渡されました。そのエラーメッセージでは、pic-urlは配列ではなく文字列です。文字列に複数のURLが含まれている場合は、分割などでそれらを抽出する必要があります。それ以外の場合は、pic-urlが配列ではない理由を理解して修正する必要があります。このコードが機能するはずです。 – pdoherty926
ああ、それは私がそれを理解することができますか悪いので – NooBskie