我正在写一个带有选择的插入:
my_object_id = 7
id_list = [1,2,4,5]
TEST_TEMPLATE = %Q{
INSERT INTO tests
(test_id, data_id, text, created_at, updated_at)
select #{my_object_id}, data_id, text, created_at, updated_at
from tests where id in (#{id_list})
}
ActiveRecord::Base.connection.execute(TEST_TEMPLATE);
我收到无法更改常量的错误。如何将值注入字符串,以便在插入/选择语句中使用它?
如何在 Ruby 中解决这个问题?