How to pass parameters sql query in find by sql
The documentation explains it all. You do it like this, where author_id and start_date are the parameters passed in.
Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date]
http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-c-find_by_sql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With