如何在 Rails 3 中使用两个设计模型(用户和管理员)实现独立的管理员(命名空间或范围)?
将此视为一个挑战,而不是其一般方法。我提到这一点的原因是,通常首选将管理员可访问的功能合并到公共面向站点。这就是所需要的:
- 为用户、访问面向公众的网站的访问者
- 设计模型为管理员
- 命名空间设计模型或将管理“区域”范围限定为
/admin
。管理员只能从此路径登录。 - 用户可以直接从网站面向公众的登陆页面进行注册;他们不会被迫按照默认设计生成的路线访问
/users/sign_up
。 - 考虑覆盖默认的设备控制器
谢谢, 麦克风。
Consider this as a challenge rather than its general approach. The reason I mention this is because, it is generally preferred to incorporate admin-accessible features into the public facing site. This is what's required:
- Devise model for Users, visitors accessing the public facing site
- Devise model for Admins
- Namespace or scope the admin 'area' to
/admin
. Admins can only login from this route. - Users can sign up directly from the site's public facing landing page; they are not forced to visit
/users/sign_up
as per the default devise generated route. - Consider overriding the default devise controllers
Thanks,
Mike.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下似乎我已经在正确的方向上取得了一些进展;这至少为用户和管理员提供了相同的开箱即用的设计功能,以及自定义路由,
想法?
警告:在此示例中,我在管理模型中包含了 :registerable devise 模块,只是用于开发期间的测试。
sign_up
路由最终将被删除。经过大量搜索(注意双关语),以下博客文章似乎要指示覆盖设备控制器,需要重新映射其所有指定的“HTTP 动词”;这是有道理的,因为未映射的将由默认设备控制器处理。
如果有人有更多使用多个设计模型和独立管理方法的经验,我将对您的想法和建议非常感兴趣!
The following seems like I've made some progress in the right direction; this at least provides identical out-of-the-box devise functionality for both users and admins, with the custom routing,
Ideas?
caveat: in this example, I've included the :registerable devise module in the Admin model just for testing during development. The
sign_up
route will, ultimately, be removed.Much searching yielded (mind the pun) the following blog post that seems to indicate overriding a devise controller requires the re-mapping of all its specified 'HTTP verbs' as it were; this makes sense as unmapped ones would be handled by the default devise controller.
If anyone has more experience working with multiple devise models and the separated admin approach, I would be very much interested in your thoughts and suggestions!