The following SQL I am trying to run is returning sql_string of “SELECT id FROM people WHERE id IN (“16”)“:
@ids = ["1", "6"]
sql_string = <<-SQL
SELECT id
FROM people
WHERE id IN ("#{@ids}")
SQL
Can someone please help modify the above query so it will create the sql_string of “SELECT id FROM people WHERE id IN (1, 6)“
Just throwing
@idsin the query will concatenate the array and give you"16". You’ll want to run@ids.join(',')to comma separate them. Plus you need to wrap the expression part of the string in#{}. Otherwise it will treat it as literal.P.S. There are very few valid reasons for manually writing a whole SQL query in Rails. You should look into using ActiveRecord to do something like
People.find_all_by_id(@ids)instead.