Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 链接_中的锚定标记到_Ruby On Rails_Html_Anchor - Fatal编程技术网

Ruby on rails 链接_中的锚定标记到

Ruby on rails 链接_中的锚定标记到,ruby-on-rails,html,anchor,Ruby On Rails,Html,Anchor,发现很难提出问题,这是我的问题。 alert.html :show,:id=>lp.id%> 当我点击链接时,我会显示页面 show.html 表格显示在页面的开头,在代码的下面 <div id="comments"> <%= render :partial=>'comments' %> </div> '注释'%> 我需要的是,当我点击链接评论时,它必须正常加载显示页面,但应该指向页面的评论部分 编辑:就像在这个stackoverflo

发现很难提出问题,这是我的问题。

alert.html


:show,:id=>lp.id%>
当我点击链接时,我会显示页面

show.html

表格显示在页面的开头,在代码的下面

 <div id="comments">
  <%= render :partial=>'comments' %>
 </div>

'注释'%>
我需要的是,当我点击链接评论时,它必须正常加载显示页面,但应该指向页面的评论部分


编辑:就像在这个stackoverflow.com中发生的那样,当你点击收件箱消息时,在左上方的StackExchange

听起来你想要的是带有路径帮助器的
锚定
选项。假设您正在使用RESTful路由,您应该能够执行以下操作:

<%= link_to "Comments", my_model_path(lp, anchor: 'comments') %>


您需要将
my_model
更改为无论您的资源调用什么。因此,如果您在routes.rb中有
资源:articles
,那么它将是
article\u路径(lp,anchor:'comments')
为您的评论div提供一个ID,并使用它链接如下:

<%= link_to "Comment##{lp.id}", :action=>:show %>
:show%>

如果div注释有您的ID,它将直接转到该位置。

我这样使用它,并正确地使用了:show,:ID=>lp.ID,:anchor=>“lessonplan\u注释”%>
<%= link_to "Comment##{lp.id}", :action=>:show %>