Reputation: 457
I read something about SQL Injection in Rails, but things are pretty unclear for me. For example, I didn't understand if code like the one listed below is safe from SQL Injection or not.
User.where("first_name like ? ", "%#{params[:q]}%")
If not, what's the alternative?
Upvotes: 1
Views: 124
Reputation: 14949
Yes, this is safe. ActiveRecord will use a prepared statement after sanitising your parameters to prevent SQL injection.
The Rails guides give more information: http://guides.rubyonrails.org/security.html#sql-injection
Upvotes: 1