开发者

Subdomains rails 3

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 fir开发者_运维问答m 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 method url_for that you modified (if you followed the Railscasts closely) is probably not used for the named url.

Try using url_for instead.

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_for method. However, does support a :host parameter so you need to write something like

... root_url(:host => "#{current_firm.subdomain}.domain.tld") ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜