Created
June 29, 2015 07:33
-
-
Save sigra/41408911f56ecc1aefdf to your computer and use it in GitHub Desktop.
Rails. Access to flash messages from lib classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_filter :globalize_session, :error_to_flash | |
protected | |
def globalize_session | |
Thread.current[:session] = session | |
end | |
def error_to_flash | |
if session[:error].present? | |
flash[:warning] = session.delete(:error) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeClass | |
def initialize(error = nil) | |
if Thread.current[:session].present? | |
Thread.current[:session][:error] = error | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment