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