Module: Spurs::Flash::ControllerMods

Defined in:
lib/spurs/flash/controller_mods.rb

Instance Method Summary collapse

Instance Method Details

#flash_addItem(list_name, message) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/spurs/flash/controller_mods.rb', line 5

def flash_addItem(list_name, message)
  pluralized_list_name = list_name.to_s.pluralize.parameterize.to_sym
  if flash[pluralized_list_name].nil?
    flash[pluralized_list_name] = Array.new
  end
  flash[pluralized_list_name].push("<p>#{message}</p>")
end

#flash_addItemWithActions(list_name, message, actions) ⇒ Object

Array of name type (:link or :js) action



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/spurs/flash/controller_mods.rb', line 17

def flash_addItemWithActions(list_name, message, actions)
  if flash[list_name].nil?
    flash[list_name] = Array.new
  end
  flash_string = "<p>#{message}</p><div class=\"alert-actions\">"

  actions.each do |action|
    if action[:type] == :link
      flash_string = flash_string + "<a class=\"btn small\" href=\"#{action[:action]}\">#{action[:name]}</a>"
    end
  end

  flash_string = flash_string +"</div>"
  flash[list_name].push(flash_string)
end

#flash_addModelErrors(model) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/spurs/flash/controller_mods.rb', line 33

def flash_addModelErrors(model)
  if flash[:errors].nil?
    flash[:errors] = Array.new
  end
  model.errors.each do |k, errs|
    flash[:errors].push("#{k.to_s} - #{errs.to_s}")
  end
end