【问题标题】:how to use subdomain with link_to rails如何使用带有 link_to rails 的子域
【发布时间】:2015-07-15 07:24:47
【问题描述】:

我有问题,我无法解决。

routes.rb 中的这段代码

Rails.application.routes.draw do

  namespace :admin do
    constraints subdomain: 'admin' do
      root to: "home#index"
      concern :supportable do
        resources :supports, only: [:new, :create]
      end
      resources :users, concerns: :supportable do
        collection do
          get 'search'
        end
      end
    end
  end
end

我想在 Ruby on Rail 中使用 link_to 进行链接。示例:<%= link_to admin_users_path do %> 但在视图中显示href="/admin/users"。如果我点击链接重定向到http://admin.example.com/admin/users。但是这个链接不正确。我想重定向链接http://admin.example.com/users

如何使用 link_to 但将 html 呈现为href="/users"

谢谢,

【问题讨论】:

    标签: ruby-on-rails subdomain link-to


    【解决方案1】:

    namespace 中使用path:'/' 尝试此代码,为我工作:

    Rails.application.routes.draw do
    
      namespace :admin, path: '/' do
        constraints subdomain: 'admin' do
          ...
        end
      end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多