[英]how to add a string to the path in link_to of ruby on rails
For example I have this code: 例如,我有以下代码:
<%= link_to "Start", start_path(:id=>1,:box=>1)%>
the id
and the box
are parameters right? id
和box
是参数吗? and for example, it generated this url: http://localhost:3000/start?id=1&box=1 例如,它生成了以下网址: http:// localhost:3000 / start?id = 1&box = 1
How can I add a string to it, to make look like this: 我如何添加一个字符串,使其看起来像这样:
http://localhost:3000/start?id=1&box=1#box_1 http:// localhost:3000 / start?id = 1&box = 1#box_1
Use the :anchor
key: 使用
:anchor
键:
<%= link_to "Start", start_path(:id => 1, :box => 1, :anchor => 'box_1')
And to answer your first question, yes, id
and box
are parameters. 要回答您的第一个问题,是的,
id
和box
是参数。 They are passed in to the request as part of the params
hash. 它们作为
params
哈希的一部分传递到请求中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.