I have a simple question I can’t figure out.
I have a rails 3 app using subdomains.
A firm have many users. When a user log in, I want to redirect them to their firms subdomain.
I’ve used Ryan Bates screencast to get subdomains working.
http://railscasts.com/episodes/221-subdomains-in-rails-3
In my user_sessions_controller I have.
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
@firm = current_user.firm
flash[:notice] = "Successfully logged in."
redirect_to root_url(:subdomain => @firm.subdomain)
else
render :action => 'new'
end
end
This sends the user in the firm with subdomain lizz to this url
http://lvh.me:3000/?subdomain=lizz
when the user is logged in this link works
<%= link_to current_firm.subdomain, root_url(:subdomain => current_firm.subdomain) %>
Do you have any ideas on how to redirect from the controller to the subdomain?
I think you problem is that you are url the named url
root_url. The helper methodurl_forthat you modified (if you followed the Railscasts closely) is probably not used for the named url.Try using
url_forinstead.Edit
The names urls are generated in actionpack-3.0.x/lib/action_dispatch/routing/route_set.rb and will not use your custom
url_formethod. However, does support a:hostparameter so you need to write something like