简体   繁体   中英

anchor tag in link_to

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.

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')

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM