[英]Subdomains in Rails 3 in url helpers
I'm trying to get this working, but it keeps using the subdomain I'm already at http://railscasts.com/episodes/221-subdomains-in-rails-3 我试图让这个工作,但它继续使用我已经在http://railscasts.com/episodes/221-subdomains-in-rails-3的子域
In url_for when I debug, it shows options[:host] as what I'd expect (subdomain.domain.com), but super just return 'accounts/sign_up' without the full path. 在我调试的url_for中,它显示了我期望的选项[:host](subdomain.domain.com),但超级只返回'accounts / sign_up'而没有完整路径。 That doesn't feel right.
这感觉不对。
What's going on? 这是怎么回事? Here's what I have:
这就是我所拥有的:
module UrlHelper
def with_subdomain(subdomain)
subdomain = (subdomain || "")
subdomain += "." unless subdomain.empty?
[subdomain, request.domain, 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 set_mailer_url_options
ActionMailer::Base.default_url_options[:host] = with_subdomain(request.subdomain)
end
end
I tried devise and non-devise helpers: 我尝试了设计和非设计助手:
= link_to 'Plan', new_plan_path(:subdomain => 'mysubdomain')
= link_to "Sign up", new_registration_path(resource_name, :subdomain => 'mysubdomain');
UPDATE: When I follow the code, it eventually calls: 更新:当我按照代码,它最终调用:
_routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys)
where 哪里
_routes.url_for(options || {}) # -> "/accounts/sign_in"
and 和
(url_options).symbolize_keys # -> {:host=>"test.lvh.me:3000", :protocol=>"http://", :_path_segments=>{:action=>"new", :controller=>"devise/passwords"}, :script_name=>""}
Still not sure how to work around it. 仍然不确定如何解决它。
事实证明我想要使用'path'help',而不是'url'帮助器:(。所以,为了完成这项工作,你需要使用root_url,而不是root_path等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.