如何使 Rails 中的链接散列化?
在我的 Rails 应用程序中,我使用 jQuery BBQ 进行 hashchange 深度链接等...
这是我在 Rails 中现有的链接:
<%= link_to('View on Site ', project_topic_url(@project.id, @topic, :only_path => false),) %>
我在 user_mailer 中工作,通过电子邮件发送...
问题是这样生成的: http://www.site.com/project/1/topic/23
我想要的是: http://www.site.com/#/project/1/topic/23
关于如何使 url 中的哈希 # 成为 ajax、深度链接友好的任何想法?
谢谢
in my rails app I'm using jQuery BBQ for hashchange deeplinking etc...
Here are my existing links in rails:
<%= link_to('View on Site ', project_topic_url(@project.id, @topic, :only_path => false),) %>
I have this working in a user_mailer that gets emailed out...
problem is this generated: http://www.site.com/project/1/topic/23
And What I want is: http://www.site.com/#/project/1/topic/23
Any ideas on how I can get the hash # in the url to be ajax, deeplinking friendly?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您始终可以创建一个辅助方法来为您处理这个问题。
然后只需调用它而不是默认的链接助手。
更新:我为您找到了解决方案。
它更干净,但我意识到这并不完全是您想要的。
对于绝对路径,它看起来像这样(有点脏):
You could always create a helper method to handle this for you.
Then just call that instead of the default link helper.
Update: I found a solution for you.
It's cleaner, but not exactly what you were looking for I realize.
For absolute paths, it would look like this (a bit dirtier):
而且你最好把它包装成一个助手
And you'd better to wrap it as a helper
也许有点晚了;但是您可以将整个路由文件打包在哈希范围内,如下所示:
使用 Rails 3.2.8,运行
rake paths
它会产生所需的结果。不确定这会如何影响您的观点或 jQuery-BBQ
bit late perhaps; but you could pack your entire routes file in a hash scope like so:
With Rails 3.2.8, running
rake routes
it yielded the desired results.Not sure how this would affect your views or jQuery-BBQ for that matter