Hi. In the Amazon/Ruby module. when someone searches for an item, and it''s not found on amazon''s side, there''s a nasty error page that is displayed. I''d simply like to test if there are no results, to redirect to a controller/action inside my rails app. In the search.rb amazon file, in the RDoc, it says that if a block is available, it will throw it all into @products, but if not it seems to go here within the search.rb file: class SearchError < StandardError; end or would it help if i put the ruby/amazon module inside my rails app? Thank you very much. PS: the error: Amazon::Search::Request::SearchError (Invalid Asin : 0234526345): C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/amazon/search.rb:1173:in `get_args'' C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/amazon/search.rb:1224:in `parse'' C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/amazon/search.rb:1143:in `initialize'' C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/amazon/search.rb:1036:in `search'' C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/amazon/search.rb:648:in `asin_search'' -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Oct 18, 2006, at 2:55 PM, Dominic Son wrote:> In the Amazon/Ruby module. when someone searches for an item, and it''s > not found on amazon''s side, there''s a nasty error page that is > displayed. I''d simply like to test if there are no results, to > redirect > to a controller/action inside my rails app.That''s amazon/ruby throwing an exception, just like ActiveRecord will if you call find with an invalid ID. There''s more about exceptions at: http://www.rubycentral.com/book/tut_exceptions.html What you want to do is to put your request to amazon/ruby inside a begin/rescue block. eg. begin result = req.asin_search(asin_value.to_s) create_instance_from_amazon(result.products[0]) rescue # Handle the error, redirect, or whatever end # Handle the result, continue execution James. -- James Stewart : Freelance Web Developer Work : http://jystewart.net/process/ Play : http://james.anthropiccollective.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you Mr James. Now for the re-directing. I guess I should put the amazon/ruby files in my rails app''s public html to get it to re-drect properly to one of my controller/actions now. James Stewart wrote:> On Oct 18, 2006, at 2:55 PM, Dominic Son wrote: >> In the Amazon/Ruby module. when someone searches for an item, and it''s >> not found on amazon''s side, there''s a nasty error page that is >> displayed. I''d simply like to test if there are no results, to >> redirect >> to a controller/action inside my rails app. > > That''s amazon/ruby throwing an exception, just like ActiveRecord will > if you call find with an invalid ID. There''s more about exceptions at: > > http://www.rubycentral.com/book/tut_exceptions.html > > What you want to do is to put your request to amazon/ruby inside a > begin/rescue block. eg. > > begin > result = req.asin_search(asin_value.to_s) > create_instance_from_amazon(result.products[0]) > rescue > # Handle the error, redirect, or whatever > end > # Handle the result, continue execution > > James. > > > -- > James Stewart : Freelance Web Developer > Work : http://jystewart.net/process/ > Play : http://james.anthropiccollective.org-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Oct 18, 2006, at 3:49 PM, Dominic Son wrote:> Thank you Mr James. Now for the re-directing. I guess I should put the > amazon/ruby files in my rails app''s public html to get it to re-drect > properly to one of my controller/actions now.You''re probably best off putting the amazon/ruby files under RAILS_ROOT/lib/ and then calling them from a controller or model (depending on how you''re using them). For example: require ''amazon/search.rb'' class MyController < ApplicationController include Amazon::Search def amazon_search req = Request.new(dev_key, associates_id) result = req.asin_search(asin_value.to_s) # do something with your result rescue redirect_to :action => ''error_page'' end def error_page end end You might want to take a look at my loads_from_amazon plugin: http://jystewart.net/process/archives/2006/07/loads_from_amazon-ruby- on-rails-plugin/ James. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---