stewart715
stewart715

Reputation: 5637

using variables in find_by_sql

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 standard practice in rails for pulling data using SQL and using variables from helpers, or other @variables ?

Thanks :)

Upvotes: 1

Views: 851

Answers (2)

Sameer C
Sameer C

Reputation: 2797

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

enclose sql query in []

Upvotes: 5

Dogbert
Dogbert

Reputation: 222428

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.

Upvotes: 2

Related Questions