Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I escape Ruby string interpolation?

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?

like image 591
Teflon Ted Avatar asked Jan 12 '10 21:01

Teflon Ted


Video Answer


1 Answers

Put single quotes around the delimiter:

has_many :foos, :finder_sql = <<-'SQL'
  select * from foos where bars = #{id}
SQL
like image 152
mckeed Avatar answered Sep 30 '22 11:09

mckeed