1

I have the next model with a array field:

Class Invitation
 include Mongoid::Document
 include Mongoid::Timestamps::Created
 include Sunspot::Mongo

 # this is the relation. Is not a field
 has_many :recipients, :class_name => 'Invitation', :foreign_key => :recipient_id
 attr_accessible :recipients

 searchable do
  string :recipients, :multiple => true do
    recipients.map { |r| r.recipients.to_s }
  end
end

I have in my controller:

def recipients

 @invitation = Invitation.find(params[:id])
 @search = Invitation.search do |s|
 s.fulltext params[:search]
 s.with(:recipients, @invitation.recipients)
 end

@recipients = @search.results
  respond_to do |format|
   format.html
  end

end

The line incorrect is @search = Invitation.search do |s|

I get the next error:

NoMethodError (undefined method `gsub' for ["#<Invitation:0x9a1c6e8>"]:Array):

How can can I fix this problem?¿ Thank you

hyperrjas
  • 10,666
  • 25
  • 99
  • 198
  • can you put a complete backtrace please ? – shingara Mar 15 '12 at 13:03
  • @shingara I load with ajax the content I can not see full trace in console log. How can I get the full trace in console log? – hyperrjas Mar 15 '12 at 13:17
  • I have edited the question the relation is `has_many :recipients, :class_name => 'Invitation', :foreign_key => :recipient_id`. – hyperrjas Mar 15 '12 at 14:25
  • You say the error is at `@search = Pin.search do |s|` but that line doesn't exist. I think the incorrect line is `@search = Invitation.search do |s|` – TCopple Mar 15 '12 at 15:14
  • Sorry @TCopple the error is in `@search = Invitation.search do |s|` – hyperrjas Mar 15 '12 at 15:50
  • @hyperrjas At the location of the error, you could do something like the following to get the backtrace to return temporarily.
    raise; rescue => e; return e.backtrace
    – BookOfGreg Feb 01 '14 at 11:51

0 Answers0