views:

442

answers:

1

Given this code:

has_many :foos, :finder_sql = <<-SQL
  select * from foos where bars = #{id}
SQL

The #{id} part is being prematurely interpolated.

How do I escape it?

Thanks.

+10  A: 

Put single quotes around the delimiter:

has_many :foos, :finder_sql = <<-'SQL'
  select * from foos where bars = #{id}
SQL
mckeed
Described here - http://www.cs.auckland.ac.nz/references/ruby/doc_bundle/Manual/man-1.4/syntax.html#here_doc
Gareth