Rails: link_to - passing a subdomain
Asked Answered
T

1

6

I need to create a link_to to a different subdomain.

This is what I came up with:

= link_to "Link to Subdomain", root_path(subdomain: "abc", param1: "value1", param2: "value2")


It is not working though. I get redirected to:

http://lvh.me:3000/?param1=value1&param2=value2

Note: The as param passed subdomain is not being displayed in the url. Neither as subdomain nor as parameter.

Instead I want to get redirected to the following URL:

 http://abc.lvh.me:3000/?param1=value1&param2=value2
Throwback answered 3/2, 2017 at 0:50 Comment(0)
M
10

Ah... you are using root_path which by definition is a relative url (ie it does not contain the domain)... you probably want root_url which will fully specify the domain (and subdomain).

Mayfield answered 3/2, 2017 at 1:53 Comment(2)
Thank you! Cannot believe I missed that :-)Throwback
:D it happens to all of us... way more often than we like to admit ;)Mayfield

© 2022 - 2024 — McMap. All rights reserved.