Dan*_*Dan 6 subdomain ruby-on-rails
如果用户在
blah.com/items/index
Run Code Online (Sandbox Code Playgroud)
如何将它们重定向到
de.blah.com/items/index
Run Code Online (Sandbox Code Playgroud)
以某种方式适用于任何页面?现在我正在使用
<%= link_to 'German', root_url(:host => 'de' + '.' + request.domain + request.port_string) %>
Run Code Online (Sandbox Code Playgroud)
但是他们将它们重定向到de.blah.com.如何保留网址的其余部分?我正在使用rails 3.
<%= link_to 'German', params.merge({:host => with_subdomain(:de)}) %>
Run Code Online (Sandbox Code Playgroud)
在应用程序/helpers/url_helper.rb
module UrlHelper
def with_subdomain(subdomain)
subdomain = (subdomain || "")
subdomain = "" if I18n.default_locale.to_s == subdomain
subdomain += "." unless subdomain.empty?
[subdomain, request.domain(tld_length), request.port_string].join
end
def url_for(options = nil)
if options.kind_of?(Hash) && options.has_key?(:subdomain)
options[:host] = with_subdomain(options.delete(:subdomain))
end
super
end
def tld_length
tld_length = case Rails.env
when 'production' then 2
when 'development' then 0
else 0
end
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3652 次 |
| 最近记录: |