# Modalbox rails var interpolation

**URL:** <https://www.ruby-forum.com/t/modalbox-rails-var-interpolation/167179>\
**Category:** Rails\
**Created:** [May 5, 2009, 6:41am UTC](https://www.ruby-forum.com/t/modalbox-rails-var-interpolation/167179 "2009-05-05T06:41:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [May 5, 2009, 6:41am UTC](https://www.ruby-forum.com/t/modalbox-rails-var-interpolation/167179/1 "2009-05-05T06:41:29Z")

</div>

Howdy everyone.

I am using modalbox which is very nice an easy to use. I have this  
for an edit for a company listing:

\<%= link\_to('Manage Companies', {}, :onclick =\> 'Modalbox.show(\'/ companies/edit/#{company.id}\', {width: 600}); return false;') %\>

The link is not putting the company.id in it puts #{ company.id}. how  
do I get this to interpolate the rails variable properly?

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [May 5, 2009, 6:45am UTC](https://www.ruby-forum.com/t/modalbox-rails-var-interpolation/167179/2 "2009-05-05T06:45:42Z")

</div>

Chris H. wrote:  
[…]

> \<%= link\_to('Manage Companies', {}, :onclick =\> 'Modalbox.show(\'/ companies/edit/#{company.id}\', {width: 600}); return false;') %\>
> 
> The link is not putting the company.id in it puts #{ company.id}. how  
> do I get this to interpolate the rails variable properly?

Review your basic Ruby syntax. :). Variable interpolation only happens  
in double-quoted strings.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [May 5, 2009, 5:56pm UTC](https://www.ruby-forum.com/t/modalbox-rails-var-interpolation/167179/3 "2009-05-05T17:56:43Z")

</div>

Ok, why does this work?

\<%= button\_to\_function “Add Site”, remote\_function( :url =\>  
{ :controller =\> ‘addsites’, :action =\> “addsitetomop”, :id=\>  
@mop}, :with =\> "‘site[comp\_#{company.id}]=’ + $(‘site\_comp\_#  
{company.id}’).value + ‘&site[customer\_#{company.id}]=’ + $  
(‘site\_customer\_#{company.id}’).value ")%\>

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [May 5, 2009, 11:36am UTC](https://www.ruby-forum.com/t/modalbox-rails-var-interpolation/167179/4 "2009-05-05T11:36:54Z")

</div>

This is because single quoted strings are not interpolated. You need  
to use doubles or any of the other string quoting methods.

Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
Learn: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)  
Twitter: [http://twitter.com/random8r](http://twitter.com/random8r)

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [May 5, 2009, 6:05pm UTC](https://www.ruby-forum.com/t/modalbox-rails-var-interpolation/167179/5 "2009-05-05T18:05:19Z")

</div>

Chris H. wrote:

> Ok, why does this work?
> 
> \<%= button\_to\_function “Add Site”, remote\_function( :url =\>  
> { :controller =\> ‘addsites’, :action =\> “addsitetomop”, :id=\>  
> @mop}, :with =\> "‘site[comp\_#{company.id}]=’ + $(‘site\_comp\_#  
> {company.id}’).value + ‘&site[customer\_#{company.id}]=’ + $  
> (‘site\_customer\_#{company.id}’).value ")%\>

For the exact reason that I posted. Read my first post again and spot  
the differences!

Really, if you can’t answer that question yourself after reading this  
thread, you need to sharpen your powers of observation before you have  
any business programming in _any_ language.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
