我有一个模型
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :meetings, :dependent => :destroy do
def find_foreign
Meeting.where("user_id <> ?", id)
end
end
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
end
当我试图让用户的外国会议像这样
some_user.meetings.find_foreign
我收到一个错误
NoMethodError (undefined method `id' for []:ActiveRecord::Relation):
因为 find_foreign 中的 self 是一个数组。如何从此方法中检索 User.id ?