【问题标题】:How do I link_to a route outside of a subdomain?如何链接到子域之外的路由?
【发布时间】:2012-11-15 18:39:24
【问题描述】:

我的路线:

class ActionDispatch::Routing::Mapper
  def draw routes_name
    instance_eval(File.read(Rails.root.join('config', 'routes', "#{routes_name}.rb")))
  end

routes_a.rb

root :to => 'home#index'
controller :home do
  post 'terms'

routes_b.rb

root :to => 'business/dashboards#show'

如果我当前在子域中,community.website.com,我会创建一个 link_to:

= link_to 'Here', terms_path

它返回为community.website.com/terms,而不是website.com/terms

如何返回website.com/terms

【问题讨论】:

    标签: ruby-on-rails routes subdomain


    【解决方案1】:

    把这个放在 routes.rb 中:

    constraints(:host => /community.website.com/) do
      match '/terms', :to => redirect {|params, request| "http://website.com/terms"}
    end
    

    【讨论】:

      【解决方案2】:

      通常我不会回答自己的问题,但我认为这会很有用:

      terms_url(host: request.domain)
      

      host: request.domain 删除子域引用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-28
        • 2017-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多