Is there a way to prepare an SQL statement like that built by ActiveRecord where()
method (using named placeholders):
Client.where("created_at >= :start_date AND created_at <= :end_date",
{start_date: params[:start_date], end_date: params[:end_date]})
I have to use this in CASE .. END
statement after ORDER BY
clause (or in SELECT
to create a computed column) to protect it from SQL injection.
EDIT:
I have to retrieve all the ActiveRecord models by this query too. So can I use find_by_sql()
? (trying...).
EDIT2:
find_by_sql()
can't use named placeholders (:start_date
in the above code example).
It's Rails 3.2.11
EDIT3:
Sorry, it can use with an Array as one parameter (find_by_sql with array format in Rails 3).