vendredi 19 février 2016

Ruby on rails devise flash messages

I'm using devise gem in my application. After logging out i redirect user to the home page. When I go to log in page again, I see "You have been logged out" message from previous session. It happens even if I refresh my home page 20 times. Here's my devise_error_messages! method's code:

def devise_error_messages!
flash_errors = []
flash_notices = []

if !flash.empty?
  flash_errors.push(flash[:error]) if flash[:error]
  flash_errors.push(flash[:alert]) if flash[:alert]
  flash_notices.push(flash[:notice]) if flash[:notice]
end

return "" if resource.errors.empty? && flash_errors.empty? && flash_notices.empty?

# not important output styling
errors = resource.errors.empty? ? flash_errors : resource.errors.full_messages
error_icon = "<span class=\"glyphicon glyphicon-exclamation-sign\" aria-hidden=\"true\">&nbsp;</span>"
errors = errors.map { |msg| "<p>" + error_icon + msg + "</p>" }.join
errors = "<div class=\"alert alert-danger\" role=\"alert\">" + errors + "</div>" unless errors.empty?

notice_icon = "<span class=\"glyphicon glyphicon-ok\" aria-hidden=\"true\">&nbsp;</span>"
notices = flash_notices.map { |msg| "<p>" + notice_icon + msg + "</p>" }.join
notices = "<div class=\"alert alert-success\" role=\"alert\">" + notices + "</div>" unless notices.empty?

html = <<-HTML
<div id="error_explanation">
  #{errors}
  #{notices}
</div>
HTML

html.html_safe
end

I'm using Rails 4.2.3, ruby 2.2.2 and devise 3.4.1. Is there any way to get rid of that old message? Any help would be appreciated. Thank you!

Aucun commentaire:

Enregistrer un commentaire