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 -- Posted via http://www.ruby-forum.com/.
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
--
Posted via http://www.ruby-forum.com/.
> 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? -- Posted via http://www.ruby-forum.com/.
On Dec 5, 2005, at 12:02 AM, rickthemick wrote:> 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 >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-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org
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-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.orgHi 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 -- Posted via http://www.ruby-forum.com/.