I want to offer another option. The way you use should work, but why not just use AJAX to show the error msg when there is any error. What the response JS does is to add the extra styles to show the error msg.
I need to use jQuery to test if the form contains a Rails error
message and override the "display: none;" style (or toggle the modal
window to display) when the page is rendered.
Take a look at http://www.twitmark.me/. Try sign in with twitter. Input a faked invitation code and see what the error looks like. Is this a better solution?