说明:
order_type是我定义的Redemption表中的一个属性,是通过查询语句
redep = Redemption.where(company_id: @company.id,appointment_id: @res.id)
但是当我使用时
redep.order_type
却报错:
undefined method `order_type' for #<ActiveRecord::Relation []>
解决:
redep = Redemption.where(company_id: @company.id,appointment_id: @res.id)
这句查询语句返回的是一个[]数组,所以数组自然没有这个方法了 。修改查询语句为(如下)即可
Redemption.where(company_id: @company.id,appointment_id: @res.id).first