# Link\_to\_remote

**URL:** <https://www.ruby-forum.com/t/link-to-remote/167652>\
**Category:** Rails\
**Created:** [May 11, 2009, 6:34am UTC](https://www.ruby-forum.com/t/link-to-remote/167652 "2009-05-11T06:34:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsmecham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f475e1/32.png) [@jsmecham](https://www.ruby-forum.com/u/jsmecham)\
**Post date:** [May 11, 2009, 6:34am UTC](https://www.ruby-forum.com/t/link-to-remote/167652/1 "2009-05-11T06:34:18Z")

</div>

I’m trying to execute a javscript block using link\_to\_remote

here’s my code:

\<%= link\_to\_function(“Add a follow-up date for this note?”, nil, :id  
=\> “show\_link”) do |page| %\>  
\<% page[:follow\_up\_date\_select].visual\_effect :toggle\_appear %\>  
\<% page[:show\_link].replace\_html “Hide date select” %\>  
\<% end %\>

It’s throwing some errors that I can’t figure out:

syntax error, unexpected ‘)’  
@output\_buffer.concat " "; @output\_buffer.concat((  
link\_to\_function(“Add a follow-up date for this note?”, nil, :id =\>  
“show\_link”) do |page| ).to\_s); @output\_buffer.concat “\n”

---

<div class="post-metadata">

**Author:** ![jsmecham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f475e1/32.png) [@jsmecham](https://www.ruby-forum.com/u/jsmecham)\
**Post date:** [May 11, 2009, 7:19am UTC](https://www.ruby-forum.com/t/link-to-remote/167652/2 "2009-05-11T07:19:28Z")

</div>

Solution :-  
\<%= link\_to\_function(“Add a follow-up date for this note?”, nil, :id  
=\> “show\_link”) do |page|  
page[:follow\_up\_date\_select].visual\_effect :toggle\_appear  
page[:show\_link].replace\_html “Hide date select”  
end %\>

---

<div class="post-metadata">

**Author:** ![jsmecham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f475e1/32.png) [@jsmecham](https://www.ruby-forum.com/u/jsmecham)\
**Post date:** [May 11, 2009, 9:41pm UTC](https://www.ruby-forum.com/t/link-to-remote/167652/3 "2009-05-11T21:41:46Z")

</div>

Siddick E. wrote:

> Solution :-  
> \<%= link\_to\_function(“Add a follow-up date for this note?”, nil, :id  
> =\> “show\_link”) do |page|  
> page[:follow\_up\_date\_select].visual\_effect :toggle\_appear  
> page[:show\_link].replace\_html “Hide date select”  
> end %\>

That worked.

I’ve set up link\_to\_function with a block that inserts a chunk of html  
from a partial when the link is clicked – namely a data select. I’m  
wondering if I can use the same block to replace the link that’s  
executing the function?

For example, after a user clicks on “Add a follow-up-date” and the date  
select appears, is there an easy way for me to replace the link with a  
“nevermind” or something that can then removed the date select? Or  
should I have the partial render a button that takes it away, instead of  
trying to update the add link? Here’s the exact code I’m using now.

\<%= link\_to\_function(“Add a follow-up date?”, nil, :id =\>  
“add\_follow\_up\_link”) do |page|  
page.insert\_html :after, ‘add\_follow\_up\_link’, :partial =\>  
‘follow\_up’  
page.visual\_effect :toggle\_appear, “follow\_up\_date\_select”  
end %\>

And here’s the partial:

 \<%= date\_select (:action\_date, :order =\> [:month, :day, :year]) %\>

My instinct is to just add a button in the partial that will call  
another javascript function to take this away. But the other problem  
with leaving the add link functioning on the page after it’s been  
clicked is that if a user accidentally clicks on it again, the partial  
is rendered again and I have two identical date\_selects on the page.
