我已經在我的應用程式中安裝了 gem rails_admin 現在我想將此 url eritheia-labs.localhost:3000/admin/dashboard重定向到localhost:3000/admin/dashboard
我想通過localhost:3000/admin而不是eritheia-labs.localhost:3000/admin訪問 Rails 管理員, 或者如果輸入此 url,它會將我重定向到 localhost:3000/admin
uj5u.com熱心網友回復:
您可以將以下內容添加到您的 config/routes.rb
constraints(host: "eritheia-labs.localhost") do
match '/admin/(*path)' => redirect { |params, req|
"http://localhost:3000#{req.fullpath}"
}, via: [:get, :head]
end
并確保它mount RailsAdmin::Engine在行之前。
此代碼應將對“http://eritheia-labs.localhost:3000/admin/*path”的任何請求重定向到“http://localhost:3000/admin/*path”。
uj5u.com熱心網友回復:
我在routes.rb檔案中找到了另一個解決方案......
authenticate :user, lambda { |u| u.role == "admin" } do
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
end
將此代碼 置于DomainConstraint 約束下,這樣做 將僅使用 localhost:3000/admin 訪問 rails_admin,而不使用 example.localhost:3000/admin
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/431905.html
上一篇:RubyYAML序列化和反序列化
