Ruby/Amazon nil Search Result

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.

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.