# Error occurred while evaluating nil.accepts

**URL:** <https://www.ruby-forum.com/t/error-occurred-while-evaluating-nil-accepts/91066>\
**Category:** Rails\
**Created:** [April 4, 2007, 9:34am UTC](https://www.ruby-forum.com/t/error-occurred-while-evaluating-nil-accepts/91066 "2007-04-04T09:34:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dean](https://www.ruby-forum.com/u/dean)\
**Post date:** [April 4, 2007, 9:34am UTC](https://www.ruby-forum.com/t/error-occurred-while-evaluating-nil-accepts/91066/1 "2007-04-04T09:34:28Z")

</div>

I have an index method with a respond\_to block that produces this  
error:

NoMethodError (You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.accepts):

The show method has the same respond\_to block but doesn’t error out.  
If I take the respond\_to block out of the index method, it works.

If I give index params[:keywords] I get this error:

Amazon::Search::Request::TypeError (non-existent/unimplemented search  
type: accepts):

Any advice?

Thanks,  
–Dean

def index  
unless params[:keywords].nil?  
@books = Array.new  
request = Amazon::Search::Request.new( DEV\_TOKEN, ASSOCIATE\_ID,  
‘us’ )  
response = request.keyword\_search( params[:keywords] ) do |  
product|  
@books.push( Book.new( ) )  
end  
end  
respond\_to do |f|  
f.html { }  
f.js { }  
end  
end

def show  
@book = Book.find(params[:id])  
respond\_to do |f|  
f.html { }  
f.xml { render :xml =\> @book.to\_xml }  
f.js { }  
end  
end
