如何获得相同的查询结果:
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)
答案 0 :(得分:0)
您可以使用send
Test.where(name: "Depeche Mode").send(@desired_field.to_sym)