简体   繁体   中英

how to use subdomain with link_to rails

I have issue and I can't fix it.

This code in 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

I want to use link_to in Ruby on Rail for link. example : <%= link_to admin_users_path do %> but in view show href="/admin/users" . if I click to link redirect to http://admin.example.com/admin/users . But this link incorrect. I want to redirect link http://admin.example.com/users .

How to use link_to but render to html as href="/users" .

Thanks,

Try this code with path:'/' in namespace , work for me:

Rails.application.routes.draw do

  namespace :admin, path: '/' do
    constraints subdomain: 'admin' do
      ...
    end
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM