rails 4 how to use where and where in condition simultaneously

activerecord, ruby-on-rails, ruby-on-rails-4

Solution

model_ids = model.split(",").map(&:to_i)
@posts = Post.where(category_id: id, product_model_id: model_ids)

or

model_ids = model.split(",").map(&:to_i)
@posts = Post.where("category_id = ? AND product_model_id IN (?)", id, model_ids)

Problem

I have the following query ``` model = (1,2,3,4) @posts = Post.where(category_id: id, product_model_id: model) ``` My above query is justing taking the `1` from model how can i use `where in` condition over here Edit-1 This piece of code works but I don't feel this as a good code right? ``` @posts = Post.where("category_id = ? and product_model_id in (#{model})", id) ``` Edit-2 If I use @posts = Post.where("category_id = ? and product_model_id in (?)", id, model) Throwing error as `invalid input syntax for integer: "15,16"` because my input is like this `select * from posts where category_id=5 and product_model_id in ('15,16')` How to correct it then..

Original source