我有这个疑问在轨:Ruby on Rails的查询
Extra.where("form_type = ?", 1)
不过,我想补充一个过滤器,这样的状态也必须是阿拉巴马州。我怎样才能做到这一点?我试过,但它不会提前上班
Extra.where("form_type = ?", 1).and("state = ?", "Alabama")
感谢
我有这个疑问在轨:Ruby on Rails的查询
Extra.where("form_type = ?", 1)
不过,我想补充一个过滤器,这样的状态也必须是阿拉巴马州。我怎样才能做到这一点?我试过,但它不会提前上班
Extra.where("form_type = ?", 1).and("state = ?", "Alabama")
感谢
使用散列来指定和条件:
Extra.where(:FORM_TYPE => 1,:状态=> “阿拉巴马”)
给这个一杆
Extra.where("form_type = ? AND state = ?", 1, "Alabama")
其不工作由于某种原因。 '@extra = Extra.where(“form_type =?AND state =?”,“corporation”,“Arizona”)' 并且我已经提取了像这样@ extra.each do | extra | – Jake
@Jake你试过一个数组:'Extra.where(“form_type =?AND state =?”,[1,“Alabama”])' –
当然,在meta_where解决方案:
Extra.where( :form_type >> 1 &:state >>%'Alabama')
作品像一个魅力 – Jake
有没有办法我可以做到这一点,以便它不区分大小写?例如,如果在数据库中它是“阿拉巴马”而不是“阿拉巴马”,它仍然会返回结果? – Jake
Jake,区分大小写将取决于您在数据库表上使用的排序规则。 –