所以,我希望能够在rails控制台日志中重现这样的错误:
D, [2015-06-30T13:41:57.442121 #3] DEBUG -- : (1.0ms) BEGIN
D, [2015-06-30T13:41:57.444003 #3] DEBUG -- : SQL (1.1ms) INSERT INTO "tracking_browsers" ("campaign_id", "channel_id", "browser_id", "hits") VALUES ($1, $2, $3, $4) RETURNING "id" [["campaign_id", 6], ["channel_id", 3], ["browser_id", 4], ["hits", 1]]
D, [2015-06-30T13:41:57.446468 #3] DEBUG -- : (2.0ms) COMMIT
D, [2015-06-30T13:41:57.449973 #3] DEBUG -- : Unit Load (1.3ms) SELECT "units".* FROM "units" WHERE "units"."campaign_id" = $1 AND "units"."unit_media_id" = $2 [["campaign_id", 6], ["unit_media_id", 2]]
NoMethodError: undefined method `/' for nil:NilClass
理想情况下,我希望能够复制粘贴此行:
SELECT "units".* FROM "units" WHERE "units"."campaign_id" = $1 AND "units"."unit_media_id" = $2 [["campaign_id", 6], ["unit_media_id", 2]]
进入像ActiveRecord::Base.connection.execute
这样的SQL方法,但由于方括号,这似乎不起作用。
我知道我可以用值6和2替换$ 1和$ 2,并删除最后一个括号,就像这样,但它很麻烦:
ActiveRecord::Base.connection.execute('SELECT "units".* FROM "units" WHERE "units"."campaign_id" = 6 AND "units"."unit_media_id" = 2')
是否有任何方法可以让我只是复制过去而无需手动修改$参数并删除括号?