在URL Rails路由中添加哈希参数 [英] Adding Hash parameter in the URL Rails Routes

查看:209
本文介绍了在URL Rails路由中添加哈希参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在link_to中添加哈希参数。我需要生成这样的URL。

  / p / generate /#sometext 

这就是我现在的代码。

 链接到点击,my_path 

如何将hash参数添加到我的路线方法中。 / p>

现在要回答



当我发布问题时,我没有完全通过url helpers API。
http://api.rubyonrails.org/classes/ActionView/ Helpers / UrlHelper.html#method-i-link_to



我现在做了。 :)。我找到了答案。

 链接到点击,my_path(:anchor => sometext)$ b下方的$ b  

下面的M.cypher几乎得到了它。 :)

解决方案

您通常会这样做:

  link_to Click,my_path(:anchor => sometext)

您的路线与它没有多大关系,因为锚点部分( #something )不会传输到服务器,因此它是一个纯客户端,附带的东西。


How to add a hash parameter in link_to. I need to generate a URL something like this..

/p/generate/#sometext

This is how my code looks now.

link_to "Click",my_path

How to add the hash parameter to my routes method.

Now for the answer

When I posted the question, I didn't got through the url helpers API fully. http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

I did now. :) .I found the answer.

link_to "Click", my_path(:anchor => "sometext")

M.cypher below almost got it. :)

解决方案

This is how you would usually do it:

link_to "Click", my_path(:anchor => "sometext")

Your routes don't have much to do with it, since the anchor part (#something) is not transferred to the server, it's a pure client-side thing.

这篇关于在URL Rails路由中添加哈希参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆