NoMethodError: undefined method `attrs'

96 views
Skip to first unread message

Greg

unread,
May 10, 2011, 6:28:57 PM5/10/11
to rs...@googlegroups.com
Hi all

I'm having some trouble adding a Rails model object to the Solr index:

doc = DocumentModel.first
solr = RSolr.connect
solr.add doc

NoMethodError: undefined method `attrs' for #<DocumentModel:0x000001040b4140>

RSolr seems to be looking for an `attrs` instance method on the object. I cannot find any reference to this in the Rails API. Where should this be inherited from, or do I need to define it myself?

Many thanks
Greg

matt mitchell

unread,
May 10, 2011, 9:06:54 PM5/10/11
to rsolr
Hi Greg,

So what RSolr is expecting is a simple hash object for adding. So what
you'd want to do is creating a mapper, that takes your DocumentModel
instance, and convert it into a Hash representation of a Solr doc.
Assuming your model is an ActiveRecord like class:

doc = DocumentModel.first
solr = RSolr.connect
solr_doc = {
:id => doc.id,
:title => doc.title
}
response = solr.add solr_doc

Does that make sense?

Matt

Greg

unread,
May 11, 2011, 12:38:10 PM5/11/11
to rs...@googlegroups.com
Hi Matt

That makes sense. Many thanks.

Greg
Reply all
Reply to author
Forward
0 new messages