2

Found it difficult to frame the question, here's my problem.

alert.html

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

when I click on the link it takes me to show page

show.html

table is displayed at beginning of the page after that, below part of code.

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

what I need is, when I click on link Comment it must load show page as normal but should direct to comments part of page.

Edit: Just like as it happens in this stackoverflow.com, on top left StackExchange when you click on inbox message.

4

2 回答 2

6

It sounds like what you want is the anchor option with a path helper. Assuming you're using RESTful routing, you should be able to do something like:

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

You would need to change my_model to the whatever your resource is called. So if you have resources :articles in routes.rb, it would be article_path(lp, anchor: 'comments')

于 2013-07-19T11:23:51.737 回答
0

Give your comment div an ID and use it link this:

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

If the div comment has your ID, it will straight go to that spot.

于 2013-07-19T11:24:43.113 回答