Rails 中类似 Drupal 的路由系统
我正在尝试找到一种最佳实践,允许用户在 Rails 中定义页面的路由,方法是在提交帖子时将其写入文本字段,就像 Drupal 中的 Path 模块一样(是的,我们正在将 Drupal 站点移植到 Rails)
因此,我需要
- 在文章提交时定义一个新的命名路由(例如 http://www.domain.com/a-day-in-annas-life)
- 通过执行 301 重定向来更改文章编辑时的现有路由(如果他们定义了新路由)从旧路线到新路线
我怎样才能最好地实现这一目标?
I am trying to find a best-practice to allow users to define the route to their pages in Rails, by writing them in a text field when submitting posts, like with the Path module in Drupal (yes, we are porting a Drupal site to Rails)
So, I need to
- define a new, named route on article submission (eg http://www.domain.com/a-day-in-annas-life)
- change the existing route on article edit, if they define a new one, by doing a 301 redirect from the old route to the new one
How can I best achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我找到了一种方法,但它是否是最佳实践,我不能说。
我正在使用这样的自定义限制器:
当我为每个应该能够响应永久链接的模型/控制器对创建这样的块时,我可以让它们都有机会对永久链接进行操作。然而,这也意味着它们都会被串联调用,这并不一定是理想的。
Okay, I found a way, but if it's best practice or not, I cant say.
I am using custom restrictor's like this:
When I create a block like this for each of my model/controller pairs that should be able to respond to permalinks, I can have them all have a chance to act on a permalink. However, this also means that they all get called in series, which is not necessarily ideal.