I have a query:
@results = the_db.where('name LIKE ?', '%#{input}%').paginate(
:page => params[:page],
:per_page => 50,
:group => "name",
:order => [
"CASE WHEN name like '#{input}%' THEN 0
WHEN name like '% %#{input}% %' THEN 1
END, name"
]
)
The problem is that this is vulnerable to injections. (The order clause) How do I solve this problem? Is it possible to somehow sanitize the user’s input to negate any attacks?
You can use the
sanitize_sql_arraymethod. Unfortunately, it is a private method, so you have to call it withsend.