#<属性::ActiveRecord_Relation 的未定义方法“id”

undefined method `id' for #<Property::ActiveRecord_Relation

抱歉这个愚蠢的问题

这里,当我加注时 @property 我正在排队,但当我加注时 @property.id 它显示 undefined method id 给我结论

owner.rb

has_many :properties

property.rb

belongs_to :owner

在owners_controller.rb

def new    
user = User.friendly.find(current_user.slug)
@owner = user.owner
authorize @owner
@property = Property.where(owner_id: @owner)
#raise @property.id.inspect
@renter = User.friendly.find(params[:renter_id]).renter  
@message = Message.new(renter_id: @renter.id, owner_id: @owner.id,property_id: @property.id)
end

提前致谢

正如我所说,where returns 一个 Active Record 关系是一个 array。尝试以下

raise @property.first.id

改变这个

@property = Property.where(owner_id: @owner)

@property = Property.find_by(owner_id: @owner)