J-P Teti
J-P Teti

Reputation: 23

Rails redirect_to subdomain of account using simple syntax

I'm a Rails noob and I'm sure this is fairly straightforward but I'm not sure how to do it, so I'm going to ask for help.

Here's my situation. I have a Rails 3 app. The app follows the subdomain as account key pattern like Basecamp does. What I would like to do is redirect to the subdomain using this syntax (let's say the current account is @account).

redirect_to @account

Currently, (as it should), this redirects to /accounts/(@account.id). What I would like to do is make it redirect to (@account.subdomain).myapp.com. Is there any way to do this?

Upvotes: 2

Views: 859

Answers (1)

intellidiot
intellidiot

Reputation: 11228

You can use:

redirect_to "http://#{@account.subdomain}.myapp.com/"

Upvotes: 5

Related Questions