开发者

Rails 3 where query

I am sending an array from jquery via the url requerts to the ra开发者_运维百科ils controller.

when I do this in my controller

log_array = (params[:log_ids])
logger.debug "This is the array #{log_array.to_a}"

I get this in my server log

This is the array 85,84,83,82

I am trying this query to get all the selected logs:

@logs = Log.where(['"logs"."id" IN (?)', log_array])

I get this on the server log

SELECT "logs".* FROM "logs" WHERE ("logs"."id" IN ('85,84,83,82'))

It sould be like this

SELECT "logs".* FROM "logs" WHERE ("logs"."id" IN (85,84,83,82))

It seems like it puts the arry in like a string.

Is there any way to make the sql right for an array?


You're making things too SQL-ish. Try this:

Log.find_all(params[:log_ids])


Or Log.where(:id => params[:log_ids]) if you want to use where() goodness.


Would use the .where listed below...check out the link to the rails 3.1 deprecations.

http://m.onkey.org/active-record-query-interface

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜