# 500 when using url\_for helper in controllers initialize

**URL:** <https://discuss.rubyonrails.org/t/500-when-using-url-for-helper-in-controllers-initialize/10245>\
**Category:** rubyonrails-talk\
**Created:** [March 14, 2007, 6:49pm UTC](https://discuss.rubyonrails.org/t/500-when-using-url-for-helper-in-controllers-initialize/10245 "2007-03-14T18:49:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_Szuminski](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@Rafael\_Szuminski](https://discuss.rubyonrails.org/u/Rafael_Szuminski)\
**Post date:** [March 14, 2007, 6:49pm UTC](https://discuss.rubyonrails.org/t/500-when-using-url-for-helper-in-controllers-initialize/10245/1 "2007-03-14T18:49:33Z")

</div>

It seems like you can't use the url\_for helper in the initialize method of a controller:

class TestController \< ApplicationController &nbsp;&nbsp;def initialize &nbsp;&nbsp;&nbsp;&nbsp;@somevar = url\_for ( :action =\> 'index' ) #\<=== This errors out for some reason &nbsp;&nbsp;end

&nbsp;&nbsp;def some\_method &nbsp;&nbsp;&nbsp;&nbsp;@somevar = url\_for ( :action =\> 'index' ) #\<=== but this works &nbsp;&nbsp;end end

Any idea why this is happening? Is there a known work around?

Thanks

Rafael

---

<div class="post-metadata">

**Author:** ![Rafael\_Szuminski](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@Rafael\_Szuminski](https://discuss.rubyonrails.org/u/Rafael_Szuminski)\
**Post date:** [March 14, 2007, 10:29pm UTC](https://discuss.rubyonrails.org/t/500-when-using-url-for-helper-in-controllers-initialize/10245/2 "2007-03-14T22:29:04Z")

</div>

thanks

---

<div class="post-metadata">

**Author:** ![RSL](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@RSL](https://discuss.rubyonrails.org/u/RSL)\
**Post date:** [March 15, 2007, 3:27pm UTC](https://discuss.rubyonrails.org/t/500-when-using-url-for-helper-in-controllers-initialize/10245/3 "2007-03-15T15:27:48Z")

</div>

If you use/d named routes you can/could just use index\_url instead of having to assign a variable.

RSL
