子域 Rails 3
我有一个简单的问题我无法弄清楚。
我有一个使用子域的 Rails 3 应用程序。
一个公司有很多用户。当用户登录时,我想将他们重定向到他们的公司子域。
我使用 Ryan Bates 截屏视频来使子域正常工作。 http://railscasts.com/episodes/221-subdomains-in-rails-3
在我的 user_sessions_controller 中我有。
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
您
对
http://lvh.me:3000/?subdomain=lizz
当用户登录时,这会将具有子域 lizz 的公司中的用户发送到此 url 此链接有效
<%= link_to current_firm.subdomain, root_url(:subdomain => current_firm.subdomain) %>
如何从控制器重定向到子域有任何想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的问题是你的url是命名的url
root_url
。您修改的辅助方法url_for
(如果您密切关注 Railscasts)可能不会用于指定的 url。尝试使用
url_for
代替。编辑
名称 url 在 actionpack-3.0.x/lib/action_dispatch/routing/route_set.rb 中生成,不会使用您的自定义
url_for
方法。但是,确实支持:host
参数,因此您需要编写类似的内容I think you problem is that you are url the named url
root_url
. The helper methodurl_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