redirect_to an :anchor not working

In my noddy blog app I want to not have to scroll back down after deleting
an entry.

I first tried using Javascript scrollTop in the view, but I could not
find a way of passing the value to the controller so that I could pass
it back to the view. I hope an expert can describe what methods, if
any, can be used to pass values from a view to an action (without
using a form). This seems to be poorly documented.

So I decided to use anchors instead (which is probably the correct way).
Each blog entry in the view gets an id=X attibute (X = 1,2,3,etc). If I
delete entry 4 then I want to scroll to entry 4-1=3.

In the index view:-

<% for comment in @comments %>
<% return_to=return_to+1 %>
  <div class="comment" id="<%= return_to %>">
  <%= link_to 'Delete', comment_path(:id =>,
  :return_to => return_to-1, :post_id => @post),:method => :delete %>

Hovering over the delete link of entry 4 I see the following URL displayed
at the bottom of FireFox:-


In the destroy action I redirect_to index and specify an :anchor parameter:-

format.html { redirect_to :action => 'index', :anchor =>
params[:return_to],:post_id => params[:post_id] }

The :anchor parameter is automatically propagated thru the :index action
as it appears in the browser's URL field. :-


Unfortunately the browser does not actually scroll down to the specified

However if I then hit Enter on the URL it does jump to the anchor!!

Does anyone know how to get anchors working properly?

PS as you can see I am using REST but probably not to the full extent,
since I have post_id=23 when in fact I should probably have something
like/post/23/comment/56. but that is another issue


'3' isn't a valid ID field in XHTML. You need to prefix it with some
non-numerical string. e.g.:


for an element with an attribute: id="_3"

Or, better: #post_3 for id="post_3"

Does that fix it?

Oops, replied to author instead of thread.

I believe this is caused by use of a numeric ID, which is invalid
XHTML. Use ids that begin with a letter, or an underscore.

I tried changing the IDs from id="1" to id="anchor_1" in order to follow xhtml
better. It id not help. (the ids are on DIVs by the way)

I should reiterate that the anchors do work OK when I hit Enter on the URL
(after an unsuccessful test)(for both id formats)

This suggest that there is nothing wrong with the anchors in the xhtml page
and it is more likely something about the redirect_to or firefox that is not
quite right


thanks for the suggestion to clean up the xhtml. This did not fix the problem
but a nother of other ones instead,

I fixed the main problem by disabling my old javascript attemt to scroll to
the correct position using scrollTop. so a false alarm on my part. sorry

anchors now work!