Search code examples
ruby-on-railssubdomainlink-to

how to pass params to link_to root_url when using subdomain


I am trying to get the link to go to

admin.mysite.com/articles/new 

and currently am using

link_to 'new article', [root_url(subdomain: 'admin), 'articles/new'].join

but am sure there's a better (rails) way to do it. Any ideas?


Solution

  • You can use the URL helper with subdomain as below:

    link_to 'new article', new_article_url(subdomain: 'admin')
    

    Assuming new_article_url will points to articles/new.