Forum: Ruby on Rails link_to_remote

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
27ee418c810e50632485c592ae512e2c?d=identicon&s=25 rickthemick (Guest)
on 2005-12-02 16:35
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
27ee418c810e50632485c592ae512e2c?d=identicon&s=25 rickthemick (Guest)
on 2005-12-05 09:02
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
F3ada405ce890b6f8204094deb12d8a8?d=identicon&s=25 Guest (Guest)
on 2005-12-05 18:09
> 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?
8e44c65ac5b896da534ef2440121c953?d=identicon&s=25 ezra (Guest)
on 2005-12-05 18:47
(Received via mailing list)
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 Zygmuntowicz
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
ezra@yakima-herald.com
27ee418c810e50632485c592ae512e2c?d=identicon&s=25 rickthemick (Guest)
on 2005-12-06 08:32
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 Zygmuntowicz
> Yakima Herald-Republic
> WebMaster
> http://yakimaherald.com
> 509-577-7732
> ezra@yakima-herald.com

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 <div>'s and in order to do this
I generate javascript funtions in one special <div> which updated the
other using update_element_function, like this:

<div id='A'>
</div>
<div id='B'>
</div>


<!-- here a make two update_element_fucntion to update A and B. Nothing
here is static data all is dynamically from a config file. Also, the
different divs contains <select>'s and are dependent on each other...
-->
<div id='updater'>

</div>

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
27ee418c810e50632485c592ae512e2c?d=identicon&s=25 rickthemick <rsm@home.se> (Guest)
on 2005-12-06 09:46
Seems to be no problem at all after taking a look at my code, thanks
again for your input!

/R
This topic is locked and can not be replied to.