# Output link\_remote\_to in helper

**URL:** <https://www.ruby-forum.com/t/output-link-remote-to-in-helper/124074>\
**Category:** Rails\
**Created:** [December 24, 2007, 12:22pm UTC](https://www.ruby-forum.com/t/output-link-remote-to-in-helper/124074 "2007-12-24T12:22:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [December 24, 2007, 12:22pm UTC](https://www.ruby-forum.com/t/output-link-remote-to-in-helper/124074/1 "2007-12-24T12:22:55Z")

</div>

Hi all,

I have a complex link\_remote\_to link I need to generate often. I want  
to DRY up my view and create a helper that generates this  
link\_remote\_to for me.

Is there a way my helper can output the link\_remote\_to javascript?

Thanks  
STijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [December 24, 2007, 2:44pm UTC](https://www.ruby-forum.com/t/output-link-remote-to-in-helper/124074/2 "2007-12-24T14:44:18Z")

</div>

On Dec 24, 2007, at 5:22 AM, Tarscher wrote:

> Hi all,
> 
> I have a complex link\_remote\_to link I need to generate often. I want  
> to DRY up my view and create a helper that generates this  
> link\_remote\_to for me.
> 
> Is there a way my helper can output the link\_remote\_to javascript?

I haven’t actually tried this, but I’m thinking it should work. Since  
link\_to\_remote is just a helper, I don’t see why you couldn’t create  
a helper that calls it. Something like:

def my\_link\_to\_remote()  
link\_to\_remote   
end

It wouldn’t be hard to find out.

Peace,  
Phillip

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [December 24, 2007, 3:47pm UTC](https://www.ruby-forum.com/t/output-link-remote-to-in-helper/124074/3 "2007-12-24T15:47:05Z")

</div>

nope, tried that but that doesn’t work.

I’ll have to put it in a partial I think.

Regards,  
Stijn

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [January 10, 2008, 6:19pm UTC](https://www.ruby-forum.com/t/output-link-remote-to-in-helper/124074/4 "2008-01-10T18:19:15Z")

</div>

On Jan 10, 2008, at 10:46 AM, Tarscher wrote:

> else  
> link\_to\_remote1  
> link\_to\_remote2  
> end
> 
> It always just outputs 1 linkto\_remote (the second). I’m I doing  
> something wrong?

You are experiencing one of the niceties of Ruby: the last “thing” in  
a method gets returned.

You will want to capture the output of both calls to link\_to\_remote  
and return them together. I have _not_ tried this, but somethiing  
like this should work

link\_string = ‘’

link\_string = link\_to\_remote blahblahblah  
link\_string += \<something to separate the links, maybe a   
 ?\>  
link\_string += link\_to\_remote blahblahblah

return link\_to\_string

Peace,  
Phillip

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [December 24, 2007, 4:35pm UTC](https://www.ruby-forum.com/t/output-link-remote-to-in-helper/124074/5 "2007-12-24T16:35:08Z")

</div>

On Dec 24, 2007, at 8:46 AM, Tarscher wrote:

> nope, tried that but that doesn’t work.

You might want to do some more research then. I just did a simple  
test like this:

In a view template

\<%= my\_link\_to\_remote ‘Click here’, ‘wgg’, ‘link\_to\_test’,  
‘link\_to\_target’ %\>

in the helper

def my\_link\_to\_remote(label, controller, action, update)  
link\_to\_remote label, :url =\> {:controller =\> controller, :action =\>  
action}, :update =\> update  
end

and in the controller

def link\_to\_test  
if request.xhr?  
render :text =\> Time.now.to\_s  
end  
end

And it worked as I expected it to. You should be able to pass in  
whatever args you need and call link\_to\_remote to build the link for  
you. Unless your need is extremely complex. Maybe you can post some  
example of what you’re trying to do?

Peace,  
Phillip

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [January 10, 2008, 5:46pm UTC](https://www.ruby-forum.com/t/output-link-remote-to-in-helper/124074/6 "2008-01-10T17:46:53Z")

</div>

I got it to work. The link\_to\_remote indeed just works in the helper.

I have an additional problem though:  
I want to output 2 link\_to\_remotes to my view with the helper:

I have something like  
if(condition1)  
link\_to\_remote1  
link\_to\_remote2  
else  
link\_to\_remote1  
link\_to\_remote2  
end

It always just outputs 1 linkto\_remote (the second). I’m I doing  
something wrong?

regards,  
Stijn
