RailsCasts Pro episodes are now free!

Learn more or hide this

JjP's Profile

GitHub User: DoppioJP

Comments by JjP



I'm not sure if you are still looking for the answer, but as I just went through this episode and I am going to use a similar functionality with subdomains, as you need, I guess I know the answer for your question.

  1. First of all, you can not expect to have in return of _path helper methods anything with the host. Instead use the _url helper methods. That will lead you into the 2nd point.

  2. Based on the root_url(:subdomain => @blog.name) used in the episode and thanks to the overridden url_for helper you can use the subdomain key in the options of any _url helper methods. Here we go:

articles_url(:subdomain => @blog.try(:subdomain))
=> "http://personal.lv.me:3000/articles"

I think you could also override blogs_articles_url helper method to be consistent with using nested resources way of creating urls. The below code is just an idea and should be re-factored to use all functionality of blogs_articles_url helper method, but for simplicity I put the below.

def blogs_articles_url(options = nil)
  if options.kind_of?(Blog)
    articles_url(:subdomain => options.try(:subdomain))

I think I would personally prefer to use articles_url with :subdomain option.

Hope that helps.