Ruby on rails 仅从Rails中的结果集中选择指定列
我只希望从TestDescription表中选择tp_info_false和tp_info_true列,并尝试了以下操作: 使用弹拨:Ruby on rails 仅从Rails中的结果集中选择指定列,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-3.1,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 3.1,我只希望从TestDescription表中选择tp_info_false和tp_info_true列,并尝试了以下操作: 使用弹拨: td=TestDescription.where(test_point_id:test_point.id).pluck(:tp_info_true,:tp_info_false).first 使用选择: td=TestDescription.where(test_point_id:test_point.id).select(:tp_info_true,:tp_
td=TestDescription.where(test_point_id:test_point.id).pluck(:tp_info_true,:tp_info_false).first
使用选择:
td=TestDescription.where(test_point_id:test_point.id).select(:tp_info_true,:tp_info_false).first
值1=td[0]
值2=td[1]
使用上述两种方法,我得到一个错误,说“参数的数目错误(2代表1)”。请纠正我的疑问。谢谢 您应该使用
选择,例如:
TestDescription.select([:tp_info_false, :tp_info_true])
此方法只接受一个参数。如果您想选择多个列,您需要像我一样将它们的名称放入数组中 首先查看几个链接:。。如果有人帮你解决这个问题,你不会自己去学习。这是同样的方式吗,你在代码中赋值吗?是的。。。使用从td[0]返回的值,td[1]