# Amazon API - How to display in view

**URL:** <https://www.ruby-forum.com/t/amazon-api-how-to-display-in-view/122158>\
**Category:** Rails\
**Created:** [December 5, 2007, 12:52am UTC](https://www.ruby-forum.com/t/amazon-api-how-to-display-in-view/122158 "2007-12-05T00:52:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 5, 2007, 12:52am UTC](https://www.ruby-forum.com/t/amazon-api-how-to-display-in-view/122158/1 "2007-12-05T00:52:13Z")

</div>

I am new to Ruby and am pretty sure that this has a very easy  
solution. I am querying an Amazon wishlist but am not sure how to  
display all of the results in the view. Following is the code with  
comments. Any help would be appreciated.

— amazon\_controller.rb —

# Taken from

[http://www.roryhansen.ca/2005/07/18/amazon-web-services-on-rails/](http://www.roryhansen.ca/2005/07/18/amazon-web-services-on-rails/)

require ‘amazon/search’

class AmazonController \< ApplicationController  
include Amazon::Search

ASSOCIATES\_ID = “INSERTIDHERE”  
DEV\_TOKEN = “INSERTDEVTOKENHERE”

def wishlist  
# Query Amazon  
request = Request.new(DEV\_TOKEN, ASSOCIATES\_ID, ‘us’, false)  
@response = request.wishlist\_search(‘170YZ2UOWUXV6’, weight=HEAVY)  
do |product|

```
  @product_name = product.product_name
  @list_price = product.list_price
  @our_price = product.our_price
  @image_url = product.image_url_medium
  @url = product.url
  @quantitydesired = product.quantitydesired

end

```

end

end

— wishlist.rhtml —

\<%= @product\_name %\> ![Falling Up]()   
  
List Price: \<%= @list\_price %\>  
  
Our Price: \<%= @our\_price %\>

\<% for item in @response %\>  
Array Item: \<%= item %\>  
  
\<% end %\>

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 6, 2007, 7:21am UTC](https://www.ruby-forum.com/t/amazon-api-how-to-display-in-view/122158/2 "2007-12-06T07:21:09Z")

</div>

Hi,

On Dec 4, 2007 6:51 PM, Kevin D [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

require ‘amazon/search’  
class AmazonController \< ApplicationController  
include Amazon::Search

ASSOCIATES\_ID = “INSERTIDHERE”  
DEV\_TOKEN = “INSERTDEVTOKENHERE”

def wishlist  
# Query Amazon  
request = Request.new(DEV\_TOKEN, ASSOCIATES\_ID, ‘us’, false)  
@products = request.wishlist\_search(‘170YZ2UOWUXV6’, weight=HEAVY)  
end  
end

> 

> \<%= @product\_name %\> ![Falling Up]()   
>   
> List Price: \<%= @list\_price %\>  
>   
> Our Price: \<%= @our\_price %\>

\<% @products.each do |product| %\>  
\<%= product.product\_name %\> ![Falling Up]()  
   
  
List Price: \<%= product.list\_price %\>  
  
Our Price: \<%= product.our\_price %\>  
  
  
  
  
\<% end %\>

> 

You should investigate the link\_to and image\_tag helpers to help clean  
up  
your views. After you’re comfortable with that the next level would be  
extracting the contents of the loop into a partial.

HTH,  
Michael G.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 6, 2007, 8:37am UTC](https://www.ruby-forum.com/t/amazon-api-how-to-display-in-view/122158/3 "2007-12-06T08:37:51Z")

</div>

Hi Mike,

Thanks for the reply. Still getting an error as follows:  
NoMethodError in Amazon#wishlist

Showing app/views/amazon/wishlist.rhtml where line #2 raised:

undefined method `url’ for #Amazon::Search::Response:0x25f3f64  
Extracted source (around line #2):

1: \<% @products.each do |product| %\>  
2: \<%= product.product\_name %\> ![Falling Up]()  
3:   
  
4: List Price: \<%= product.list\_price %\>  
  
5: Our Price: \<%= product.our\_price %\>  
  
RAILS\_ROOT: ./script/…/config/…

Again here are the files:  
amazon\_controller.rb

# Taken from

[http://www.roryhansen.ca/2005/07/18/amazon-web-services-on-rails/](http://www.roryhansen.ca/2005/07/18/amazon-web-services-on-rails/)

require ‘amazon/search’  
class AmazonController \< ApplicationController  
include Amazon::Search  
ASSOCIATES\_ID = “IDHERE”  
DEV\_TOKEN = “TOKENHERE”  
def wishlist  
# Query Amazon  
request = Request.new(DEV\_TOKEN, ASSOCIATES\_ID, ‘us’, false)  
@products = request.wishlist\_search(‘170YZ2UOWUXV6’,  
weight=HEAVY)  
end  
end

wishlist.rhtml  
\<% @products.each do |product| %\>  
\<%= product.product\_name %\> \<img src=“\<  
%=product.image\_url\_medium %\>” class=“” border=“0” alt=“Falling Up” /

 

> 

  
 List Price: \<%= product.list\_price %\>  
 Our Price: \<%= product.our\_price %\>  
  
  
\<% end %\>

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 6, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/amazon-api-how-to-display-in-view/122158/4 "2007-12-06T16:57:02Z")

</div>

Kevin,

On Dec 6, 2007 2:36 AM, Kevin D [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Mike,
> 
> Thanks for the reply. Still getting an error as follows:  
> NoMethodError in Amazon#wishlist
> 
> Showing app/views/amazon/wishlist.rhtml where line #2 raised:
> 
> undefined method `url’ for #Amazon::Search::Response:0x25f3f64  
> Extracted source (around line #2):

I am not at all familiar with the Amazon search library. However, it  
appears that your product object does not have a method call url.

Change this line in your controller and you should be good to go.

@products = request.wishlist\_search(‘170YZ2UOWUXV6’,  
weight=HEAVY).products

If you need more reference information check out:  
[http://www.caliban.org/ruby/ruby-amazon/classes/Amazon.html](http://www.caliban.org/ruby/ruby-amazon/classes/Amazon.html)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 6, 2007, 11:56pm UTC](https://www.ruby-forum.com/t/amazon-api-how-to-display-in-view/122158/5 "2007-12-06T23:56:11Z")

</div>

Many thanks Mike. That .product in the controller did it.
