find_by_sql with array format in Rails 3

前端 未结 1 1523
天涯浪人
天涯浪人 2021-01-02 09:16

good day guys!

I\'m using find_by_sql() in rails 3 to fetch records as follows.

@list=Email.find_by_sql([\"SELECT * FROM Emails WHER         


        
相关标签:
1条回答
  • 2021-01-02 10:09

    You can use a hash to name the interpolated values, like this:

    @list = Email.find_by_sql(["SELECT * FROM Emails WHERE (sent_id = :id OR from_id = :id)", {:id => params[:id]}])
    
    0 讨论(0)
提交回复
热议问题