如何在mongoid上按名称查询字段?

时间:2016-12-27 12:51:11

标签: ruby-on-rails ruby mongoid

如何获得相同的查询结果:

Test.where(name: "Depeche Mode").first.last_connection_date

通过字符串

更改last_connection_date
@desired_field = "last_connection_date"
Test.where(name: "Depeche Mode").first.(@desired_field)

1 个答案:

答案 0 :(得分:0)

您可以使用send

Test.where(name: "Depeche Mode").send(@desired_field.to_sym)