The reason for this is that in order to provide the DSL for building
the search (methods like 'keywords', 'with', and 'paginate' in your
example), Sunspot has to change the evaluation context of the search
block. Local variables are always retained inside blocks (blocks are
closures), and Sunspot does some Ruby dark magic so that you can still
access methods from the calling context when you're inside the search
DSL; but instance variables are very difficult to expose and so
Sunspot doesn't attempt it.
Sunspot does allow you to provide a block parameter to the DSL block,
in which case the parameter exposes the DSL, and Sunspot doesn't
change the calling context; so, the following would work:
search = Sunspot.search([Sound, UserSound]) do |query|
query.keywords @search_term
query.with :published, true
query.paginate :page => @page, :per_page => Sound.per_page
end
Hope that clears things up.
Mat
> --
> You received this message because you are subscribed to the Google Groups
> "Sunspot" group.
> To post to this group, send email to ruby-s...@googlegroups.com.
> To unsubscribe from this group, send email to
> ruby-sunspot...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/ruby-sunspot?hl=en.
>