title: rails 3 application before_filter with redirect_to
body: <p>my rails 3 apps need a before_filter for check if user are logged or not. if logged, redirect to subdomain. I use Devise for log system. After sign_up the user are redirect to his subdomain, but if he come back to the website and are logged again, he must be redirected to his subdomain again.</p>
  
  <p>I tried this :</p>
  
  <pre><code>if current_user.present?
  company_id = current_user.company_id
  @company = Company.find(company_id)
  redirect_to @company.subdomain + "." + request.domain
  end
  </code></pre>
  
  <p>with this code, the url are : www.mywebsite.comsubdomain.mywebsite.com
  Yeah, i think it's because redirect_to are for webpage not for new url.</p>
  
  <p>I tried with </p>
  
  <pre><code>if current_user.present?
  company_id = current_user.company_id
  @company = Company.find(company_id)
  root_url(:host =&gt; @company.subdomain + "." + request.domain)
  end
  </code></pre>
  
  <p>but same thing. i get the same url as previous tests.</p>
  
  <p>what can i do to redirect to my subdomain?</p>