我已经创建了一个设计用户模型.有两种类型的用户:
我已经完成了bij创建两个"正常"模型:客户和管理员.这两个模型继承自用户模型,如下所示:
class Customer < User
Run Code Online (Sandbox Code Playgroud)
有谁知道如何为每种类型的用户设置根路径.我想要这样的东西:
authenticated :customer do
root :to => "customer/dashboard#index"
end
authenticated :admin do
root :to => "admin/dashboard#index"
end
Run Code Online (Sandbox Code Playgroud)
更新:
我已经解决了这个问题:
root :to => "pages#home", :constraints => lambda { |request|!request.env['warden'].user}
root :to => 'customer/dashboard#index', :constraints => lambda { |request| request.env['warden'].user.type == 'customer' }
root :to => 'admin/dashboard#index', :constraints => lambda { |request| request.env['warden'].user.type == 'admin' }
Run Code Online (Sandbox Code Playgroud) 我在我的rails应用程序中使用了friendly_id gem,以创建漂亮干净的URL.它运作良好,但页面也可通过te记录ID获得.
例:
我有一个'name'作为slug的记录.此记录的ID为1.
所以页面可以从2个网址获得:
domain.com/name
和
domain.com/1
我只想使用domain.com/name,所以我不希望从domain.com/1获得该页面.
有谁知道如何做到这一点?