用于经过身份验证和未经身份验证的用户的 Rails 6 路由

时间:2021-06-17 10:56:13

标签: ruby-on-rails ruby-on-rails-6 rails-routing

多年前,我在 routes.rb 中使用类似的东西向用户发送不同的 URL:

unauthenticated do

  devise_scope :user do
     root :to => 'pages#home' , :as => :root_path
  end
end

root to: 'pages#home_logged_in'

并且没有问题。我为经过身份验证的和未...用户获得了 root_path。

但现在我在谷歌搜索,只能找到这样的东西:

devise_scope :user do
   authenticated :user do
     root :to => 'pages#dashboard', as: :authenticated_root
   end

   unauthenticated :user do
     root :to => 'session#new', as: :unauthenticated_root
   end
end

所以我的“旧”方法不再起作用了?我不能为两种用户设置 root_path 吗?

当然第一个脚本不起作用,我总是redirect_to pages#home。

答案:

好的,现在我只需要添加 :user 。寻求帮助太快了:)

unauthenticated :user do

end

0 个答案:

没有答案