Bind Parameters To ActiveRecord SQL Query
Many of the connection query methods that come with ActiveRecord
accept an optional binds
parameter. This can be used to safely inject parameters into the query.
Here's a SQL query we could use with one of these methods:
Notice the $1
and $2
, those are what will be bound to the two parameters included as binds
.
Notice the binds
is an array of tuples. It's the second value in each tuple that gets bound the corresponding binding indicator in the sql. The syntax is a bit awkward since it is a lower-level API, however once you know it, you can manage.
Last updated