Delete div content automatically after 2 seconds

You can also achieve this with RJS / Rails Helpers:

if the error message is set thorugh an AJAX response, you would do
something like in the rjs partial you render for the response:

page.replace_html :div_id "Your erro message here"
page.delay(2) do
  page.replace_html :div_id, ""
end

if it's a complete page refresh:

<div id="div_id"><%= @error_msg</div>
<script>
update_page do |page|
  page.delay(2) do
    page.replace_html :div_id, ""
  end
end
</script>