开发者

using variables in find_by_sql

开发者 https://www.devze.com 2023-03-23 05:21 出处:网络
I\'m really new to rails, but I\'m trying to pull some data that matches user preferences (current_user.industry) for example.

I'm really new to rails, but I'm trying to pull some data that matches user preferences (current_user.industry) for example.

Is there a stand开发者_如何学Card practice in rails for pulling data using SQL and using variables from helpers, or other @variables ?

Thanks :)


Model.find_by_sql(["SELECT .... ?", @var])

enclose sql query in []


Are you referring to escaping variables in find_by_sql statements?

You can do

Model.find_by_sql("SELECT .... ?", @var)

just like you do in .where.

0

精彩评论

暂无评论...
验证码 换一张
取 消