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

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

问题描述

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

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.

现在来回答

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

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差点就搞定了.:)

M.cypher below almost got it. :)

推荐答案

您通常会这样做:

link_to 'Click', my_path(anchor: 'sometext')

你的路由与它没有太大关系,因为锚部分 (#something) 没有传输到服务器,这是一个纯粹的客户端事情.

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 Routes 中添加 Hash 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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