开发者

Ruby on Rails Queries

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜