# Render :action =\> bla, :anchor =\> 'bla'

**URL:** <https://www.ruby-forum.com/t/render-action-bla-anchor-bla/106153>\
**Category:** Rails\
**Created:** [June 6, 2007, 9:54pm UTC](https://www.ruby-forum.com/t/render-action-bla-anchor-bla/106153 "2007-06-06T21:54:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mischa78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3da27b/32.png) [@mischa78](https://www.ruby-forum.com/u/mischa78)\
**Post date:** [June 6, 2007, 9:54pm UTC](https://www.ruby-forum.com/t/render-action-bla-anchor-bla/106153/1 "2007-06-06T21:54:33Z")

</div>

Hi,

I hope someone can help me with this.

I have a pretty long form (which involves scrolling). After posting the  
form, some data gets validated and if there are errors the form is  
rendered again and the errors are shown.

The problem is: when the form gets rendered the scroll bar is always at  
the top, instead of at the part of the form where the error happened. I  
tried using redirect\_to :anchor =\> ‘bla’, but when I use that the values  
the user entered are gone.

What I want to do is render :action =\> bla, :anchor =\> ‘bla’, but  
obviously this doesn’t work. I can’t see how to do this. Does anyone  
have an idea???

Thanks,  
Mischa.

–  
[http://boxroom.rubyforge.org](http://boxroom.rubyforge.org)

---

<div class="post-metadata">

**Author:** ![mischa78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3da27b/32.png) [@mischa78](https://www.ruby-forum.com/u/mischa78)\
**Post date:** [June 6, 2007, 10:14pm UTC](https://www.ruby-forum.com/t/render-action-bla-anchor-bla/106153/2 "2007-06-06T22:14:44Z")

</div>

My suggestion would be to use ajax to post the errors into an  
initially empty DIV. The easiest way to do this is to use an RJS  
template for the response to the form. Ajax on Rails has a good  
treatment of this.

Michael

On Jun 6, 12:54 pm, Mischa B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mischa78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3da27b/32.png) [@mischa78](https://www.ruby-forum.com/u/mischa78)\
**Post date:** [June 6, 2007, 11:33pm UTC](https://www.ruby-forum.com/t/render-action-bla-anchor-bla/106153/3 "2007-06-06T23:33:50Z")

</div>

Thanks for the tip. I found another workaround… It may not look so  
nice, but it works:

If an error occurs, call a javascript that scrolls to the anchor:

\<% if flash[:cancel\_error] %\>

\<%= flash[:cancel\_error] %\>
\<% end %\>

function scrollToError(){ window.location.hash = ‘#error’; }
