Topic: Adding anchor to URL when rendering an action containing error message
I want to add an anchor to my view when a validation error occurs. Currently the page redisplays, but my error message is below the and of the screen and cannot be seen unless the user scrolls down. I want the browser to automatically scroll down to the message.
Here is my method in the controller:
@interaction = Contact.find(params[:id]).interactions.create(params[:interaction])
@interaction.date_created = Date.today
flash[:notice] = 'The interaction was added'
redirect_to :action => 'show', :id => params[:id]
#this line renders the action with the errors, but I need to add an anchor to the URL to display
@contact = Contact.find(params[:id])
render :action => 'show', :id => params[:id]
and in the Interaction model I have a validate_presence_of call, which generates the error if that field is empty.