I’m trying to find all users except for users with an id that is a member of an array exclude_ids
Here’s what I have:
User.where("id != ?", exclude_ids)
This only works when exclude_ids has only 1 element. If it has more than one element, I get
this error:
ActiveRecord::StatementInvalid: SQLite3::SQLException: near ",": syntax error: SELECT "users".* FROM "users" WHERE (id != 1,2)
I’d appreciate any help.
I havent used Rails 3 but its unsafe to use
User.where("id in #{exclude_ids} ?").On Rails 2.x you do it as follows
Rails 3.x docs http://railsapi.com/doc/rails-v3.0.0.beta.3/classes/ActiveRecord/Base.html