# Using ERB in $() function?

**URL:** <https://www.ruby-forum.com/t/using-erb-in-function/128524>\
**Category:** Rails\
**Created:** [February 8, 2008, 12:28pm UTC](https://www.ruby-forum.com/t/using-erb-in-function/128524 "2008-02-08T12:28:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hashpipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/87869e/32.png) [@hashpipe](https://www.ruby-forum.com/u/hashpipe)\
**Post date:** [February 8, 2008, 12:28pm UTC](https://www.ruby-forum.com/t/using-erb-in-function/128524/1 "2008-02-08T12:28:56Z")

</div>

Hi,

I am new to Ajax, and I was wondering if it is possible to have an id  
passed to a $() function in runtime.

Like I am generating id for an article at runtime doing something like  
id=article-\<%= article.id %\>

Now id I want to have a toggle element on this id then can I do  
Element.toggle(’$(‘article-\<%= article.id %\>’)’, ‘blind’) as well…??..  
I cannot use the “this” parameter

Thanks and regards  
Sanjay

---

<div class="post-metadata">

**Author:** ![hashpipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/87869e/32.png) [@hashpipe](https://www.ruby-forum.com/u/hashpipe)\
**Post date:** [February 8, 2008, 12:41pm UTC](https://www.ruby-forum.com/t/using-erb-in-function/128524/2 "2008-02-08T12:41:33Z")

</div>

On 8 Feb 2008, at 11:28, Sanjay B. wrote:

> Element.toggle(’$(‘article-\<%= article.id %\>’)’, ‘blind’) as  
> well…??..  
> I cannot use the “this” parameter

If you mean runtime as in when the rjs is generated then yes:  
Element.toggle("$(‘article-#{article.id }’)", ‘blind’)  
If you mean runtime as in when the user’s browser executes the  
javascript then no.

Fred

---

<div class="post-metadata">

**Author:** ![hashpipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/87869e/32.png) [@hashpipe](https://www.ruby-forum.com/u/hashpipe)\
**Post date:** [February 8, 2008, 1:03pm UTC](https://www.ruby-forum.com/t/using-erb-in-function/128524/3 "2008-02-08T13:03:42Z")

</div>

Dosen’t seem to work like that also. Can you suggest some other  
work-around

\<%= link\_to\_function "Meta Information \>\>", "Element.toggle("$('meta- #{article.id}')", 'blind')" %\>

Thanks and regards

Frederick C. wrote:

> On 8 Feb 2008, at 11:28, Sanjay B. wrote:
> 
> > Element.toggle(’$(‘article-\<%= article.id %\>’)’, ‘blind’) as  
> > well…??..  
> > I cannot use the “this” parameter
> 
> If you mean runtime as in when the rjs is generated then yes:  
> Element.toggle("$(‘article-#{article.id }’)", ‘blind’)  
> If you mean runtime as in when the user’s browser executes the  
> javascript then no.
> 
> Fred

---

<div class="post-metadata">

**Author:** ![hashpipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/87869e/32.png) [@hashpipe](https://www.ruby-forum.com/u/hashpipe)\
**Post date:** [February 8, 2008, 1:16pm UTC](https://www.ruby-forum.com/t/using-erb-in-function/128524/4 "2008-02-08T13:16:02Z")

</div>

Ok. thanks…it’s working fine…just some syntax issues…thanks a lot  
again

Sanjay B. wrote:

> Dosen’t seem to work like that also. Can you suggest some other  
> work-around
> 
> \<%= link\_to\_function "Meta Information \>\>", "Element.toggle("$('meta- #{article.id}')", 'blind')" %\>
> 
> Thanks and regards
> 
> Frederick C. wrote:
> 
> > On 8 Feb 2008, at 11:28, Sanjay B. wrote:
> > 
> > > Element.toggle(’$(‘article-\<%= article.id %\>’)’, ‘blind’) as  
> > > well…??..  
> > > I cannot use the “this” parameter
> > 
> > If you mean runtime as in when the rjs is generated then yes:  
> > Element.toggle("$(‘article-#{article.id }’)", ‘blind’)  
> > If you mean runtime as in when the user’s browser executes the  
> > javascript then no.
> > 
> > Fred
