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/ 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 --- <!-- DEBUGGING Trying display all results. Currently only displays the first result --> <a href="<%= @url %>"><%= @product_name %> <img src="<%= @image_url %>" class="" border="0" alt="Falling Up" /> </a></br> List Price: <%= @list_price %></br> Our Price: <%= @our_price %></br> </br></br> <!-- END DEBUGGING Trying display all results. Currently only displays the first result --> <!-- DEBUGGING Displays all items but cannot filter for only the ones I want --> <% for item in @response %> Array Item: <%= item %><br/> <% end %> <!-- End DEBUGGING Displays all items but cannot filter for only the ones I want --> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, On Dec 4, 2007 6:51 PM, Kevin D <kevindiffily-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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/ > <snip> >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> <!-- DEBUGGING Trying display all results. Currently only displays > the first result -->> <a href="<%= @url %>"><%= @product_name %> <img src="<%= @image_url > %>" class="" border="0" alt="Falling Up" /> </a></br> > List Price: <%= @list_price %></br> > Our Price: <%= @our_price %></br> > </br></br> > <!-- END DEBUGGING Trying display all results. Currently only > displays the first result --> ><% @products.each do |product| %> <a href="<%= product.url %>"><%= product.product_name %> <img src="<%product.image_url_medium %>" class="" border="0" alt="Falling Up" /> </a></br> List Price: <%= product.list_price %></br> Our Price: <%= product.our_price %></br> </br></br> <% end %>> > <snip> >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 Guterl --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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: <a href="<%= product.url %>"><%= product.product_name %> <img src="<%=product.image_url_medium %>" class="" border="0" alt="Falling Up" /></a> 3: </br> 4: List Price: <%= product.list_price %></br> 5: Our Price: <%= product.our_price %></br> 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/ 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| %> <a href="<%= product.url %>"><%= product.product_name %> <img src="< %=product.image_url_medium %>" class="" border="0" alt="Falling Up" /></a></br> List Price: <%= product.list_price %></br> Our Price: <%= product.our_price %></br> </br></br> <% end %> On Dec 6, 1:20 am, "Michael Guterl" <mgut...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > On Dec 4, 2007 6:51 PM, Kevin D <kevindiff...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > 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/ > > <snip> > > 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 > > > <!-- DEBUGGING Trying display all results. Currently only displays > > the first result --> > > <a href="<%= @url %>"><%= @product_name %> <img src="<%= @image_url > > %>" class="" border="0" alt="Falling Up" /> </a></br> > > List Price: <%= @list_price %></br> > > Our Price: <%= @our_price %></br> > > </br></br> > > <!-- END DEBUGGING Trying display all results. Currently only > > displays the first result --> > > <% @products.each do |product| %> > <a href="<%= product.url %>"><%= product.product_name %> <img src="<%> product.image_url_medium %>" class="" border="0" alt="Falling Up" /> > </a></br> > List Price: <%= product.list_price %></br> > Our Price: <%= product.our_price %></br> > </br></br> > <% end %> > > > > > <snip> > > 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 Guterl--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Kevin, On Dec 6, 2007 2:36 AM, Kevin D <kevindiffily-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 <snip>On Dec 6, 1:20 am, "Michael Guterl" <mgut...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > > > On Dec 4, 2007 6:51 PM, Kevin D <kevindiff...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > 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/ > > > <snip> > > > > 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 > > > > > <!-- DEBUGGING Trying display all results. Currently only displays > > > the first result --> > > > <a href="<%= @url %>"><%= @product_name %> <img src="<%= @image_url > > > %>" class="" border="0" alt="Falling Up" /> </a></br> > > > List Price: <%= @list_price %></br> > > > Our Price: <%= @our_price %></br> > > > </br></br> > > > <!-- END DEBUGGING Trying display all results. Currently only > > > displays the first result --> > > > > <% @products.each do |product| %> > > <a href="<%= product.url %>"><%= product.product_name %> <img src="<%> > product.image_url_medium %>" class="" border="0" alt="Falling Up" /> > > </a></br> > > List Price: <%= product.list_price %></br> > > Our Price: <%= product.our_price %></br> > > </br></br> > > <% end %> > > > > > > > > > <snip> > > > > 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 Guterl > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Many thanks Mike. That .product in the controller did it. On Dec 6, 10:56 am, "Michael Guterl" <mgut...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Kevin, > > On Dec 6, 2007 2:36 AM, Kevin D <kevindiff...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > > <snip>On Dec 6, 1:20 am, "Michael Guterl" <mgut...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > > On Dec 4, 2007 6:51 PM, Kevin D <kevindiff...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > 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/ > > > > <snip> > > > > 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 > > > > > <!-- DEBUGGING Trying display all results. Currently only displays > > > > the first result --> > > > > <a href="<%= @url %>"><%= @product_name %> <img src="<%= @image_url > > > > %>" class="" border="0" alt="Falling Up" /> </a></br> > > > > List Price: <%= @list_price %></br> > > > > Our Price: <%= @our_price %></br> > > > > </br></br> > > > > <!-- END DEBUGGING Trying display all results. Currently only > > > > displays the first result --> > > > > <% @products.each do |product| %> > > > <a href="<%= product.url %>"><%= product.product_name %> <img src="<%> > > product.image_url_medium %>" class="" border="0" alt="Falling Up" /> > > > </a></br> > > > List Price: <%= product.list_price %></br> > > > Our Price: <%= product.our_price %></br> > > > </br></br> > > > <% end %> > > > > > <snip> > > > > 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 Guterl--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---