Forum: Ruby on Rails Controller url_for modifies request object?

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.
13e4ba7f654dbbdd186d702c06c8b24c?d=identicon&s=25 Morten (Guest)
on 2007-03-19 18:07
(Received via mailing list)
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
6d57db44c5a4e0721cc7f78cf0ce308a?d=identicon&s=25 Stephen Bartholomew (steveb)
on 2007-03-19 19:07
(Received via mailing list)
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
13e4ba7f654dbbdd186d702c06c8b24c?d=identicon&s=25 Morten (Guest)
on 2007-03-20 13:04
(Received via mailing list)
On Mar 19, 7:06 pm, "Steve Bartholomew" <s...@curve21.com> 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

But this has not made it to the plugin repository.

Br,

Morten
This topic is locked and can not be replied to.