# Controller url\_for modifies request object?

**URL:** <https://www.ruby-forum.com/t/controller-url-for-modifies-request-object/89343>\
**Category:** Rails\
**Created:** [March 19, 2007, 6:07pm UTC](https://www.ruby-forum.com/t/controller-url-for-modifies-request-object/89343 "2007-03-19T18:07:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![morten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/cdc98d/32.png) [@morten](https://www.ruby-forum.com/u/morten)\
**Post date:** [March 19, 2007, 6:07pm UTC](https://www.ruby-forum.com/t/controller-url-for-modifies-request-object/89343/1 "2007-03-19T18:07:31Z")

</div>

Hi,

In my controller, I do something like this:

MyMailer.deliver\_signup\_notification(url\_for(:subdomain =\>  
account.subdomain, :controller =\> ‘hello’))

And a few lines later:

redirect\_to :action =\> ‘index’

Much to my confusion, the redirect routes me to the subdomain used in  
the url\_for. I’ve tried

redirect\_to :action =\> ‘index’, :subdomain =\> nil

Which changed nothing. It gets really strange when I try:

redirect\_to :action =\> ‘index’, :subdomain =\> request.subdomains.first

Only to find that request.subdomains.first now equals  
account.subdomain - which is NOT the case before the  
“MyMailer.deliver\_signup\_notification” method. So url\_for changes the  
request object - which I personally dislike. Is there a work around  
for this?

Thanks.

Morten

---

<div class="post-metadata">

**Author:** ![morten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/cdc98d/32.png) [@morten](https://www.ruby-forum.com/u/morten)\
**Post date:** [March 19, 2007, 7:07pm UTC](https://www.ruby-forum.com/t/controller-url-for-modifies-request-object/89343/2 "2007-03-19T19:07:15Z")

</div>

I may be way off here, I just wrote this test:

def test\_should\_generate\_correct\_url  
original\_url = url\_for(:controller =\> “pages”)  
url\_with\_subdomain = url\_for(:controller =\> “pages”, :subdomain =\>  
“test”)  
latest\_url = url\_for(:controller =\> “pages”)

```
assert_equal original_url, latest_url

```

end

This passes and as far as I can see url\_for doesn’t modify anything.  
Of course it may be something to do with a plugin you have. Can you  
try something similar and let us know the results? Also, it would be  
good to know which version of Rails you’re running.

Cheers,

Steve

---

<div class="post-metadata">

**Author:** ![morten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/cdc98d/32.png) [@morten](https://www.ruby-forum.com/u/morten)\
**Post date:** [March 20, 2007, 1:04pm UTC](https://www.ruby-forum.com/t/controller-url-for-modifies-request-object/89343/3 "2007-03-20T13:04:51Z")

</div>

On Mar 19, 7:06 pm, “Steve B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This passes and as far as I can seeurl\_fordoesn’t modify anything.  
> Of course it may be something to do with a plugin you have. Can you  
> try something similar and let us know the results? Also, it would be  
> good to know which version of Rails you’re running.

Thanks for the pointer Steven, it was indeed a broken plugin  
(url\_for\_domain). There’s a fixed version on the Wiki:

[http://wiki.rubyonrails.org/rails/pages/Url+for+domain](http://wiki.rubyonrails.org/rails/pages/Url+for+domain)

But this has not made it to the plugin repository.

Br,

Morten
