Module: RailsTemporaryData::ControllerHelpers

Extended by:
ActiveSupport::Concern
Defined in:
lib/rails_temporary_data/controller_helpers.rb

Instance Method Summary collapse

Instance Method Details

#clear_tmp_data(key) ⇒ Object



16
17
18
19
20
# File 'lib/rails_temporary_data/controller_helpers.rb', line 16

def clear_tmp_data(key)
  tmp_data = TemporaryData.unexpired.find_by_id(session[key])
  session[key] = nil
  tmp_data.destroy if tmp_data
end

#get_tmp_data(key) ⇒ Object



10
11
12
13
14
# File 'lib/rails_temporary_data/controller_helpers.rb', line 10

def get_tmp_data(key)
  tmp_data = TemporaryData.unexpired.find_by_id(session[key])
  session[key] = nil if tmp_data.nil?
  tmp_data
end

#set_tmp_data(key, data, expires_at = nil) ⇒ Object



5
6
7
8
# File 'lib/rails_temporary_data/controller_helpers.rb', line 5

def set_tmp_data(key, data, expires_at = nil)
  tmp_data = TemporaryData.create!(:data => data, :expires_at => expires_at)
  session[key] = tmp_data.id
end