【发布时间】:2012-03-03 15:22:20
【问题描述】:
Rails 2.35 / Ruby 1.87
如果我有 Rails 查询:
test = Test.all
假设“test”代表的表格有一个名为“color”的字段,如:
test[0].color = 'blue'
test[1].color = 'red'
如何搜索数组以找出(例如)颜色字段 == 'orange' 的数组索引?
基本上我只想在颜色字段中找到“橙色”并获取该索引的索引#,以便我可以使用它来获取同一索引处另一个字段的值。就像如果 test[3].color == 'orange' 那么我想要那个 '3' 索引来获取 test[3].name。
谢谢!
【问题讨论】:
标签: ruby-on-rails