Ruby on rails 根带缓动导轨4布线

Ruby on rails 根带缓动导轨4布线,ruby-on-rails,ruby,friendly-url,friendly-id,Ruby On Rails,Ruby,Friendly Url,Friendly Id,目前我正在使用friendlyIDgem,如果用户经过身份验证,我只想用slug将我的应用程序重定向到根目录 url http://localhost:3000/companyABC/dashboard 这是我目前的密码 authenticated :employer do root to: redirect("/:slug/dashboard"), as: :employer_root end namespace :company, path: "/:slug" do

目前我正在使用
friendlyID
gem,如果用户经过身份验证,我只想用slug将我的应用程序重定向到根目录

url

http://localhost:3000/companyABC/dashboard
这是我目前的密码

  authenticated :employer do
    root to: redirect("/:slug/dashboard"), as: :employer_root
  end

  namespace :company, path: "/:slug" do
    resources :dashboard
    namespace :settings do
      resources :collaborators
    end
  end
但问题是当我登录时,它会将我重定向到
http://localhost:3000/:slug/dashboard

据我所知,您不能在路由中使用lambda,因此无法在路由中访问数据库并获取公司的slug

但如果您使用designe,您可以在为在路径中签名后覆盖方法,这样用户将被重定向到指定的url而不是根url。例如:

class ApplicationController < ActionController::Base
  def after_sign_in_path_for(user)
    company_dashboards_url(user.company)
  end
end
class ApplicationController

此处的更多信息:

恐怕您需要明确设置
根目录。您可以做的是,在绑定到根目录的操作中检查用户是否经过身份验证,并根据用户的身份呈现不同的视图。谢谢您给我一个提示。我想我可以请求路线上的蛞蝓。