Skip to content

Instantly share code, notes, and snippets.

@sigra
Created June 29, 2015 07:33
Show Gist options
  • Save sigra/41408911f56ecc1aefdf to your computer and use it in GitHub Desktop.
Save sigra/41408911f56ecc1aefdf to your computer and use it in GitHub Desktop.
Rails. Access to flash messages from lib classes
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
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