我想从根路径中删除子域。
我尝试将:subdomain => false
添加到root
文件中的routes.rb
命令,但没有成功:当我在网址中手动输入子域时,子域保留并且不会被删除。
示例:
my root is => lvh.me:3000
enter subdomain manually => xyz.lvh.me:3000 and hit enter then it remains the same
这是我在routes.rb
文件中尝试过的,但没有成功:
root :to => 'home#show', :subdomain => false or
root :to => 'home#show', :constraints => { :subdomain => false }, via: [:get]
答案 0 :(得分:0)
根据this comment on rails github,在Rails> = 4中,您需要使用约束来获取此值。试试这个:
constraints subdomain: false do
root to: 'home#show'
end
答案 1 :(得分:0)
@dgilperez:你的代码工作得很好,但我也需要在应用程序控制器中进行更改,是的,我找到了解决方案,我刚刚更新了
before_action :check_subdomain
def check_subdomain
unless company_signed_in?
if request.subdomain.present? && params[:controller] == "companies/registrations" && params[:action] == "new"
redirect_to root_url, subdomain: false
end
end
end
答案 2 :(得分:0)
在应用程序控制器中写这个。这将有效。
before_action :check_subdomain
def check_subdomain
unless company_signed_in?
if request.subdomain.present? && params[:controller] == "companies/registrations" && params[:action] == "new"
redirect_to root_url, subdomain: false
end
end
end