Shruthi R Shruthi R - 1 year ago 75
Ruby Question

Rails - How to query by multiple ids(array)

In rails 4, I am trying to access a ActiveRecord relation using multiple ids.

Ids are coming as

Parameters: {"ids"=>"[55, 56]"}
. In controller I am using it as
but this query returns zero results.

View path is like
user_posts_path(:ids=>[5, 6])

Right now
. How to make it only as an array?

Answer Source


User.where(:id=> JSON.parse(params[:ids]))

But I'd try to pass these ids as an array, not an array in a string, if possible.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download