# Using #{} with instance variables inside prototypes $$()

**URL:** <https://www.ruby-forum.com/t/using-with-instance-variables-inside-prototypes/160764>\
**Category:** Rails\
**Created:** [February 19, 2009, 1:47pm UTC](https://www.ruby-forum.com/t/using-with-instance-variables-inside-prototypes/160764 "2009-02-19T13:47:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scudco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@scudco](https://www.ruby-forum.com/u/scudco)\
**Post date:** [February 19, 2009, 1:47pm UTC](https://www.ruby-forum.com/t/using-with-instance-variables-inside-prototypes/160764/1 "2009-02-19T13:47:10Z")

</div>

I want to do something like this in a link\_to\_remote call in a view

:before =\> ‘$$(“tr#task\_#{completed\_task.id} \>  
td.task-title-cell”).update(“Reactivating”)’

but the number of ’ and " in the string are not allowing my  
#{completed…} to work. Its just being read as characters and not as a  
request to insert the value of the contained variable.

How do i get round this and are there any tips for this? people must be  
using #{} within their prototype code a lot and it must look messy. is  
there a cleaner way?

---

<div class="post-metadata">

**Author:** ![scudco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@scudco](https://www.ruby-forum.com/u/scudco)\
**Post date:** [February 19, 2009, 2:22pm UTC](https://www.ruby-forum.com/t/using-with-instance-variables-inside-prototypes/160764/2 "2009-02-19T14:22:00Z")

</div>

:before =\> “$$(‘tr#task\_#{completed\_task.id} \> td.task-title-  
cell’).update(‘Reactivating’)”

should do the trick. Also you probably need to add a .first() after  
your $$() selector, since it always returns an array as far as i  
know.

As for your question regarding style, I think there isn’t really a  
better alternative and also I don’t think it looks too messy … . if  
your selector gets really long and ugly you could assign it to a  
variable first, like:

selector = “tr#task\_#{completed\_task.id} \> td.task-title-cell”

and then:

:before =\> “$$(‘#{selector}’).first().update(‘Reactivating’)”

On Feb 19, 1:47 pm, Adam A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![scudco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@scudco](https://www.ruby-forum.com/u/scudco)\
**Post date:** [February 19, 2009, 2:24pm UTC](https://www.ruby-forum.com/t/using-with-instance-variables-inside-prototypes/160764/3 "2009-02-19T14:24:24Z")

</div>

your outermost quote is a single one ( ’ ). that way rails won’t  
insert the value of your variable.  
you could simply try to swap single and double quotes.  
another way would be to introduce additional variables with substrings  
or just form your string with +

example:  
array = [“big”, “little”]  
substring = array[1]  
string = “my " + substring + " string is actually quite #{array[0]}”
