# Mixing onlick functions in link\_to\_function

**URL:** <https://www.ruby-forum.com/t/mixing-onlick-functions-in-link-to-function/105796>\
**Category:** Ruby\
**Created:** [June 2, 2007, 10:03pm UTC](https://www.ruby-forum.com/t/mixing-onlick-functions-in-link-to-function/105796 "2007-06-02T22:03:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [June 2, 2007, 10:03pm UTC](https://www.ruby-forum.com/t/mixing-onlick-functions-in-link-to-function/105796/1 "2007-06-02T22:03:31Z")

</div>

Hi:

This is giving an error:

\<%= link\_to\_function “expand”,  
“Element.toggle(‘in#{msg.id}’);  
Element.show(‘col#{msg.id}’); Element.hide(‘ex#{msg.id}’);  
document.getElementById(’#{msg.id}’).style.backgroundColor = ‘white’;  
{new Ajax.Request(’/messages/msg\_read/#{msg.id}, {asynchronous:true,  
evalScripts:true})}” %\>

I’ve tried it a bunch of different ways but I still get an:

“unterminated string literal”

error.

Any help you can provide would be greatly appreciated - or Is there a  
better way?

Thanks!

Mike

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [June 2, 2007, 10:09pm UTC](https://www.ruby-forum.com/t/mixing-onlick-functions-in-link-to-function/105796/2 "2007-06-02T22:09:36Z")

</div>

Mike D. wrote:

> Hi:
> 
> This is giving an error:
> 
> \<%= link\_to\_function “expand”,  
> "Element.toggle(‘in#{msg.id}’);  
> Element.show(‘col#{msg.id}’); Element.hide(‘ex#{msg.id}’);  
> document.getElementById(’#{msg.id}’).style.backgroundColor = ‘white’;  
> {new Ajax.Request(’/messages/msg\_read/#{msg.id}, {asynchronous:true,  
> --------------------^

This quote mark isn’t closed.

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [June 2, 2007, 11:39pm UTC](https://www.ruby-forum.com/t/mixing-onlick-functions-in-link-to-function/105796/3 "2007-06-02T23:39:47Z")

</div>

On Jun 2, 2007, at 4:03 PM, Mike D. wrote:

> Mike

\<%= link\_to\_function “expand” do |page|  
page.toggle “in#{msg.id}”  
page.show “col#{msg.id}”  
page.hide “ex#{msg.id}”  
page \<\< “$(‘#{msg.id}’).style.backgroundColor = ‘white’;”  
remote\_function(:url =\> ‘/messages/msg\_read/#  
{msg.id}’) #\<\<== messages\_msg\_read\_path(msg) perhaps?  
end %\>

gives:

expand

Which is clearly easier to read (and find that missing ’ that Alex  
pointed out), right?

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
