title: RuntimeError default_url_options host and root_url (with subdomain)
body: <p>Each user of my app have a custom url (through subdomain) stored in db.</p>
  
  <p>My request is simple, I would like to send the "user url" through a json feed, like this:</p>
  
  <pre><code>{user_name: "vincent", :user_url: "vincent.my_app.com"}
  </code></pre>
  
  <p>to do that I have overwrite the as_json function of user model:</p>
  
  <pre><code>def as_json(options={})
      {
          :user_name: self.name,
          :user_url: root_url(:subdomain =&gt; self.subdomain)
      }
  end
  </code></pre>
  
  <p>I have this additionnal module (which this work great and isn't the actual problem):</p>
  
  <pre><code>module SubdomainHelper
  def with_subdomain(subdomain)
      subdomain = (subdomain || "")
      subdomain += "." unless subdomain.empty?
      host = ActionMailer::Base.default_url_options[:host]
      [subdomain, host].join
  end
  
  def url_for(options = nil)
      if options.kind_of?(Hash) &amp;&amp; options.has_key?(:subdomain)
          options[:host] = with_subdomain(options.delete(:subdomain))
      end
      super
  end
  end
  </code></pre>
  
  <p>But when I get the json feed I have this error:</p>
  
  <pre><code>RuntimeError (Missing host to link to! Please provide :host parameter or set default_url_options[:host]):
  </code></pre>
  
  <p>pointing to the "as_json" method of user model.</p>
  
  <p>of course each environment implement default_url_options, in dev.rb:</p>
  
  <pre><code>config.action_mailer.default_url_options = {:host =&gt; 'my_app:3000'}
  </code></pre>
  
  <p>I don't understand why and how I fix it. Please help me.</p>