[英]Passing current page id to a link_to (Ruby/ Rails)
Apologies if this seems a bit vague. 道歉,如果这似乎有点含糊。
Basically I have a page which loads content based on id. 基本上,我有一个页面,可根据ID加载内容。 I'm trying to put links withing it like this
我正在尝试像这样放置链接
<%= link_to 'mypage', {:action => 'mypageload', :id => '1'},{:class=>'mypages'}%>
What I'd like to do is pass the id of the current page into this link. 我想做的就是将当前页面的ID传递到此链接中。
So something like 所以像
:id => 'params[:id]'
Is there a way to do this? 有没有办法做到这一点?
删除单引号:: :id => params[:id]
Yes, you can use the params variable in the views. 是的,您可以在视图中使用params变量。 In your example you put the params inside quotes making it a string.
在您的示例中,将参数置于引号内,使其成为字符串。 Just leave those out and you should be fine, like this:
只需将这些留在外面,就可以了,就像这样:
<%= link_to 'mypage', {:action => 'mypageload', :id => params[:id]},{:class=>'mypages'}%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.