# Link\_to\_remote

**URL:** <https://www.ruby-forum.com/t/link-to-remote/93658>\
**Category:** Rails\
**Created:** [December 2, 2005, 4:35pm UTC](https://www.ruby-forum.com/t/link-to-remote/93658 "2005-12-02T16:35:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rickthemick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@rickthemick](https://www.ruby-forum.com/u/rickthemick)\
**Post date:** [December 2, 2005, 4:35pm UTC](https://www.ruby-forum.com/t/link-to-remote/93658/1 "2005-12-02T16:35:22Z")

</div>

Hi!  
I cant use funtions like link\_to\_remote in self defined calsses/objects  
used from within my controller? Is there a readon for this, I dont  
understand what libraries etc I need to include to get it running!

Best regards  
/Rickard

---

<div class="post-metadata">

**Author:** ![rickthemick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@rickthemick](https://www.ruby-forum.com/u/rickthemick)\
**Post date:** [December 5, 2005, 9:02am UTC](https://www.ruby-forum.com/t/link-to-remote/93658/2 "2005-12-05T09:02:29Z")

</div>

hi!  
Is there no one that has experienced the same problem? I’m getting sick  
of this! Is it a bad description of the problem?

If this doesnt work, there must be a good work around, or I probably  
have to leave ruby on rails. The thing is that I have an object in which  
I want to generate HTML and return it back to the controller which in  
turn displays it on the web page.

## Ok, a simple example: I want to do this in the object created from my controller:

link\_to(“MyPage”, { :action =\> “run” }, :popup =\> [‘new\_window’,  
‘height=300,width=600’])

* * *

## The error message:

NoMethodError in Init\_test#index

You have a nil object when you didn’t expect it!  
The error occured while evaluating nil.url\_for

RAILS\_ROOT: .  
Application Trace | Framework Trace | Full Trace

## #{RAILS\_ROOT}…Ruby/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action\_view/helpers/url\_helper.rb:18:in `url_for' #{RAILS_ROOT}...Ruby/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/action_view/helpers/url_helper.rb:49:in`link\_to’ …

…the same problem is with e.g link\_to\_remote()

## My includes are:

## include ActionView::Helpers::JavaScriptHelper include ActionView::Helpers::TagHelper include ActionView::Helpers::FormOptionsHelper include ActionView::Helpers::FormTagHelper include ActionView::Helpers::UrlHelper

## The url\_helper.rb (line numbers are included)

## 16: def url\_for(options = {}, \*parameters\_for\_method\_reference) 17: options = { :only\_path =\> true }.update(options.symbolize\_keys) if options.kind\_of? Hash 18: @controller.send(:url\_for, options, \*parameters\_for\_method\_reference) 19: end

I also found on the web a parameter called :controller =\> ‘ctrl\_name’  
which I thought could solve my problems since @controller at line 18  
seems to be nil. But I cant get it to work and I have not found any  
documentation around it!

/Rickard

rickthemick wrote:

> Hi!  
> I cant use funtions like link\_to\_remote in self defined calsses/objects  
> used from within my controller? Is there a readon for this, I dont  
> understand what libraries etc I need to include to get it running!
> 
> Best regards  
> /Rickard

---

<div class="post-metadata">

**Author:** ![rickthemick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@rickthemick](https://www.ruby-forum.com/u/rickthemick)\
**Post date:** [December 5, 2005, 6:47pm UTC](https://www.ruby-forum.com/t/link-to-remote/93658/3 "2005-12-05T18:47:42Z")

</div>

On Dec 5, 2005, at 12:02 AM, rickthemick wrote:

> NoMethodError in Init\_test#index  
> #{RAILS\_ROOT}…Ruby/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/  
> include ActionView::Helpers::TagHelper  
> (options.symbolize\_keys) if
> 
> > Best regards  
> > /Rickard

Rickard-

```
Link_to_remote and friends are meant to be used in your views only.

```

Why are you trying to use them in your controller? Surely there is a  
workaround you can use to move the code to the view where it belongs?

Cheers-  
-Ezra Z.  
Yakima Herald-Republic  
WebMaster  
[http://yakimaherald.com](http://yakimaherald.com)  
509-577-7732  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![rickthemick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@rickthemick](https://www.ruby-forum.com/u/rickthemick)\
**Post date:** [December 5, 2005, 6:09pm UTC](https://www.ruby-forum.com/t/link-to-remote/93658/4 "2005-12-05T18:09:52Z")

</div>

> ## I want to do this in the object created from my controller:
> 
> link\_to(“MyPage”, { :action =\> “run” }, :popup =\> [‘new\_window’,  
> ‘height=300,width=600’])
> 
> * * *

Is there a reason you can’t do this in your view?

---

<div class="post-metadata">

**Author:** ![rickthemick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@rickthemick](https://www.ruby-forum.com/u/rickthemick)\
**Post date:** [December 6, 2005, 9:46am UTC](https://www.ruby-forum.com/t/link-to-remote/93658/5 "2005-12-06T09:46:44Z")

</div>

Seems to be no problem at all after taking a look at my code, thanks  
again for your input!

/R

---

<div class="post-metadata">

**Author:** ![rickthemick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@rickthemick](https://www.ruby-forum.com/u/rickthemick)\
**Post date:** [December 6, 2005, 8:32am UTC](https://www.ruby-forum.com/t/link-to-remote/93658/6 "2005-12-06T08:32:05Z")

</div>

ezra wrote:

> On Dec 5, 2005, at 12:02 AM, rickthemick wrote:
> 
> > NoMethodError in Init\_test#index  
> > #{RAILS\_ROOT}…Ruby/lib/ruby/gems/1.8/gems/actionpack-1.10.2/lib/  
> > include ActionView::Helpers::TagHelper  
> > (options.symbolize\_keys) if
> > 
> > > Best regards  
> > > /Rickard
> 
> Rickard-
> 
> Link\_to\_remote and friends are meant to be used in your views only.  
> Why are you trying to use them in your controller? Surely there is a  
> workaround you can use to move the code to the view where it belongs?
> 
> Cheers-  
> -Ezra Z.  
> Yakima Herald-Republic  
> WebMaster  
> [http://yakimaherald.com](http://yakimaherald.com)  
> 509-577-7732  
> removed\_email\_address@domain.invalid

Hi all!  
Thanks for your replies and directions. Well, the thing is that the code  
is quite complex and I probably have deceases from previous server side  
scripting. When “link\_to\_remote” worked with just a few includes (in the  
controller) I though this was appropriate.

In more detail I want to update multiple

's and in order to do this  
I generate javascript funtions in one special 
 which updated the  
other using update\_element\_function, like this:

The update\_element\_function contains the generated HTML string  
(including the output of link\_to\_remote calls) and I guess this is not  
possible to do in the view…

/R
