开发者

Ruby on Rails Queries

开发者 https://www.devze.com 2023-03-26 05:59 出处:网络
I have this query in rails: Extra.where(\"form_type = ?\", 1)开发者_JS百科 However I would like to add a filter so the state also has to be Alabama. How can I do this? I tried this but it wouldn\'t

I have this query in rails:

Extra.where("form_type = ?", 1)开发者_JS百科

However I would like to add a filter so the state also has to be Alabama. How can I do this? I tried this but it wouldn't work

Extra.where("form_type = ?", 1).and("state = ?", "Alabama")

Thanks in advance


Use a hash to specify AND conditions:

Extra.where(:form_type => 1, :state => "Alabama")


Give this a shot

Extra.where("form_type = ? AND state = ?", 1, "Alabama")


And of course, the meta_where solution:

Extra.where(:form_type >> 1 & :state >> % 'Alabama')


Extra.where(:form_type => 1, :state => "Alabama")
0

精彩评论

暂无评论...
验证码 换一张
取 消