Using @query with Sunspot::Rails
by James
Using sunspot-rails for search in your Rails app? If like me you’re using @query to represent a search term within your Rails controllers, you might find that your searches turn up empty when they shouldn’t.
There’s a simple reason for this: used inside an Object.search block, @query evaluates to an internal Sunspot::Search object — not to your search term. Don’t worry: it’s easy to get round this issue; either rename your instance variable, or use the search block with an argument:
This ensures that @query is evaluated in the correct context.