我使用Ruby的AWS寶石與亞馬遜進行交互。我在我的控制器中測試了它,並且它工作正常,但是當我將代碼移到我的模型中時,它不能正確解析來自亞馬遜的數據。紅寶石AWS - 亞馬遜
舉例來說,在我的控制器
@items[0].medium_image.url = "http://ecx.images-amazon.com/images/I/61YIGdgh86L._SL160_.jpg"
但在我的模型
items[0].medium_umage.url = '[#<Amazon::AWS::AWSObject::URL:0x1030ba758 value="http://ecx.images-amazon.com/images/I/61YIGdgh86L._SL160_.jpg">]'
請幫幫忙!
在兩種情況下,我的代碼是:
def add_amazon_links
require 'amazon/aws'
require 'amazon/aws/search'
query = self.name
#!/usr/bin/ruby -w
#
# $Id: item_search1,v 1.4 2008/04/11 19:24:24 ianmacd Exp $
is = ItemSearch.new('All', { 'Keywords' => '#{query}' })
rg = ResponseGroup.new('Medium', 'Reviews')
req = Request.new
req.locale = 'us'
resp = req.search(is, rg)
items = resp.item_search_response[0].items[0].item
@items = resp.item_search_response[0].items[0].item
unless @items[0].blank?
self.image_url = @items[0].medium_image.url
self.a_price = @items[0].item_attributes[0].list_price[0].formatted_price
self.title = @items[0].item_attributes[0].title
self.a_url = @items[0].detail_page_url
self.save!
end
端