Bind Parameters To ActiveRecord SQL Query
sql = <<-SQL
select
coalesce(places.latitude, 41.8781) latitude,
coalesce(places.longitude, -87.6298) longitude
from places
join appointments
on places.id = apointments.places_id
where appointments.id = $1
and status = $2
SQLconnection = ActiveRecord::Base.connection
binds = [[nil, appt_id], [nil, input_status]]
coords = connection.select_one(sql, nil, binds)
coords
#=> { "latitude": 41.8781, "longitude": -87.6298 }Last updated