Can anyone help with the following? I’ve been trying to follow along
with the tutorial for making a real-time search box with Ajax
(http://wiki.rubyonrails.org/rails/pages/How+to+make+a+real-time+search+box+with+the+Ajax+helpers),
but have been hitting some snags along the way:
In the index view:
<%= observe_field ‘search’, :frequency => 0.5,
:update => ‘searchresults’, :url =>
{ :controller => ‘contacts’, :action=> ‘list’ },
:with => “‘search=’ + escape(value)” %>
In the contacts controller
def list
if @params[‘search’]
@contacts_pages, @contacts = paginate :contacts,
:order_by => ‘firstname’,
:conditions => [ ‘LOWER(firstname) LIKE ?’,
‘%’ + @params[‘search’].downcase + ‘%’ ],
:per_page => 20
@mark_term = @params[‘search’]
render_without_layout
else
@contacts_pages, @contacts = paginate :contacts,
:order_by => ‘firstname’, :per_page => 20
end
end
And then finally in the list view.
<%= @mark_term ? highlight(contact.firstname, @mark_term) :
h(contact.firstname) %>
Everytime I run it, the searchresults layer updates to show a error that
isn’t that helpful:
NoMethodError in ContactsController#list
You have a nil object when you didn’t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]