根据current best practices的说法,留言板上给定线程的RESTful URL应该如下所示:
http://domain/forum/threads/3这也是一种常见的SEO实践,URL应该包含关键字(slug),因此上面的URL可能会变成:
http://domain/forum/threads/3/title-of-this-particular-thread现在,要再次编辑这个帖子,根据我在第一段中链接的指导原则,URL将是:
http://domain/forum/threads/3/edit当有人启动一个标题为"edit“的线程时,会发生什么情况?该如何决定是显示还是编辑该线程?
发布于 2012-12-03 21:09:27
代替http://domain/forum/threads/3/title-of-this-particular-thread
你应该做http://domain/forum/threads/3-title-of-this-particular-thread
这将防止冲突,并只是作为搜索引擎优化友好。有几种方法可以实现这一点,但最简单的方法是在模型中添加一个自动执行转换的to_param方法:
class Thread < ActiveRecord::Base
to_param
"#{id}-#{title}"
end
end如果你需要更多的灵活性,或者不想在你的所有模型中重复,你可以使用friendly_id宝石。
https://stackoverflow.com/questions/13683888
复制相似问题