Im new to ruby and followed this blog to fix sql injection bug but my query is giving error .
Original query :
class Car < ActiveRecord::Base
...
has_one :Driver, lambda {
where(status: PASSENGER_STATUS, connected_number: [phone, mobile])
.order("FIELD (`classDummy`.`status`, #{PASSENGER_STATUS.join(', ')}")
}, class_name: :classDummy
Whereas , PASSENGER_STATUS is ( in other class )
PASSENGER_STATUS = [
'employed','temporary'
].freeze
SQL INJECTION fix I did
order("FIELD (`classDummy`.`status`, ? )", PASSENGER_STATUS.join(', '))
But this is throwing exception while executing query.
Exception that Im getting :
ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?,