Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoid as_document error

I am using mongoid with devise invitable,

after assigning roles to user I found the following error

"**undefined method `as_document' for Array **" , any suggestions ?

invitable = find_or_initialize_with_error_by(:email, attributes[:email])
invitable.attributes = attributes
# scope_id attribute does not set properly
invitable.roles.map {|r| r.scope_id = attributes[:roles_attributes]["0"][:scope_id]}

if invitable.persisted? && !invitable.invited?
  invitable.errors.add(:email, :taken)
elsif invitable.email.present? && invitable.email.match(Devise.email_regexp)
  invitable.invite!
end

Whats wrong I am doing ?

like image 730
bilal ahmad Avatar asked Nov 12 '22 10:11

bilal ahmad


1 Answers

This is likely because as_document doesn't work against an array, only single objects.

like image 95
Asya Kamsky Avatar answered Nov 15 '22 04:11

Asya Kamsky