Thanks Pat. It worked.
Can this be called from within a model instance method?
I tried and it did not work, but I don't quite understand why:

undefined local variable or method `sphinx_attributes' for
#<Brand:0x76ccce0>



On Sat, Nov 23, 2013 at 12:36 AM, Pat Allan <[email protected]>wrote:

> Are you running that test in the console? Be aware that panes are applied
> before the search query happens, but because the console calls inspect on
> each returned value, brands is evaluated as soon as you define it.
>
> A way to get around that is add ; ‘’ to the end of that line - thus, an
> empty string is returned instead. This means you can then add the pane, and
> *then* accessing attributes in search values should work.
>
>   brands = Brand.search(:conditions => {:name => params[:search]}, :order
> => :name, :page => params[:page], :per_page => 5); ''
>   brands.context[:panes] << ThinkingSphinx::Panes::AttributesPane
>   puts brands[0].sphinx_attributes['role_id']
>
> If this doesn’t help, let me know.
>
> —
> Pat
>
> On 23 Nov 2013, at 4:03 am, J. Garcia <[email protected]> wrote:
>
> Hi there,
>
> I'm trying to access sphinx_attributes in this setup:
>
> class Brand < ActiveRecord::Base
>
>   has_many :brand_ids
>   has_many :brand_roles, :through => :brand_ids
> end
>
> ThinkingSphinx::Index.define :brand, :with => :active_record do
>   indexes name, :sortable => true
>
>   has brand_roles.id, :as => :role_id, :type => :integer, :multi => true
> end
>
> brands = Brand.search(:conditions => {:name => params[:search]}, :order =>
> :name, :page => params[:page], :per_page => 5)
> brands.context[:panes] << ThinkingSphinx::Panes::AttributesPane
>
> puts brands[0].sphinx_attributes['role_id']
>
> undefined method `sphinx_attributes' for #<Brand:0x5c19e88>
>
> What am I missing?
>
> My versions:
> Sphinx 2.1.3
> thinking-sphinx 3.0.6
> Rails 3.2.14
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
>
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Thinking Sphinx" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/thinking-sphinx/Om7jB03FF9Y/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to