2013-07-19 59 views
2

發現難以確定問題,這是我的問題。link_to中的錨標記

alert.html

<div class="alert_text"> 
<%= link_to "Comment", :action=>:show, :id=>lp.id %> 
</div> 

當我點擊需要我展示

show.html

表頁面開始顯示的頁面鏈接之後,下面的部分代碼。

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

我需要的是,當我在鏈接評論單擊它必須加載頁面顯示正常,但應直接向頁的註釋部分。

編輯:就像,因爲它發生在這個stackoverflow.com,在上面留下StackExchange當你點擊收件箱消息

回答

5

這聽起來像你想要的是帶路徑助手的anchor選項。假設你正在使用REST風格的路由,你應該能夠做這樣的事情:

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

你需要改變my_model到無論你的資源被調用。所以,如果你在routes.rb中有resources :articles,這將是article_path(lp, anchor: 'comments')

+0

我以這種方式使用它並且正確地做到了<%= link_to「Comment」,:action =>:show,:id => lp.id,:anchor =>'lessonplan_comments'%> – Nithin

0

給您的評論的div的ID,並用它鏈接此:

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

如果DIV評論有你的ID,它會直接進入那個地方。