Rafael Szuminski
2007-Mar-14 18:49 UTC
500 when using url_for helper in controllers initialize
It seems like you can''t use the url_for helper in the initialize
method of a controller:
class TestController < ApplicationController
def initialize
@somevar = url_for ( :action => ''index'' ) #<=== This
errors out
for some reason
end
def some_method
@somevar = url_for ( :action => ''index'' ) #<=== but
this works
end
end
Any idea why this is happening? Is there a known work around?
Thanks
Rafael
--
http://www.bdcsoftware.com" - Automotive CRM
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Alex Wayne
2007-Mar-14 19:16 UTC
Re: 500 when using url_for helper in controllers initialize
Rafael Szuminski wrote:> It seems like you can''t use the url_for helper in the initialize > method of a controller: > > class TestController < ApplicationController > def initialize > @somevar = url_for ( :action => ''index'' ) #<=== This errors out > for some reason > end > > def some_method > @somevar = url_for ( :action => ''index'' ) #<=== but this works > end > end > > Any idea why this is happening? Is there a known work around? > > Thanks > > Rafael > > > -- > http://www.bdcsoftware.com" - Automotive CRMRather than initialize, try a before_filter class TestController < ApplicationController before_filter :set_some_var def index #renders index.rhtml end private def set_some_var @somevar = url_for ( :action => ''index'' ) end end Now you can use @somevar in every action that goes through your controller. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rafael Szuminski
2007-Mar-14 22:29 UTC
Re: 500 when using url_for helper in controllers initialize
thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Russell Norris
2007-Mar-15 15:27 UTC
Re: 500 when using url_for helper in controllers initialize
If you use/d named routes you can/could just use index_url instead of having to assign a variable. RSL On 3/14/07, Rafael Szuminski <raf1hh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > thanks > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---