Det ser ud til, at du har tastefejl i din kode. Forbindelsen skal være af ActiveRecord::Base.connection
men du skrev DealPrize.connection.execute
.
connection = ActiveRecord::Base.connection
connection.execute "sql query"
Prøv at ændre din kode som
after_create :create_deal_prizes
def create_deal_prizes
Deal.transaction do
connection = ActiveRecord::Base.connection
self.prizes_number.times do |i|
connection.execute "INSERT INTO ‘deal_prizes’ (deal_id) values (self.deal.id)"
end
end
end