find_by_sql in Rails, accessing the resulting array

后端 未结 5 1971
日久生厌
日久生厌 2020-12-30 17:09

I\'m trying to run a query in a very quick and dirty way in Rails, without putting the rest of the model in place. I know this is bad practice but I just need a quick resul

5条回答
  •  醉酒成梦
    2020-12-30 18:02

    @item.shipping_price.first.price
    

    or

    @item.shipping_price[0].price
    

    Thanks Atastor for pointing that out!

    When you use AS price in find_by_sql, price becomes a property of the result.

提交回复
热议问题