Module: Writefully::FlashHelper
- Defined in:
- app/helpers/writefully/flash_helper.rb
Instance Method Summary collapse
- #can_flash? ⇒ Boolean
- #flash_color ⇒ Object
- #flash_object ⇒ Object
- #flash_path ⇒ Object
- #flash_values_count ⇒ Object
- #render_flash ⇒ Object
Instance Method Details
#can_flash? ⇒ Boolean
7 8 9 10 |
# File 'app/helpers/writefully/flash_helper.rb', line 7 def can_flash? flash.keys.sort == [:from, :object_id, :object_type, :type] and \ flash.to_hash.values.compact.count == flash_values_count end |
#flash_color ⇒ Object
24 25 26 27 28 29 |
# File 'app/helpers/writefully/flash_helper.rb', line 24 def flash_color { success: 'alert-success', error: 'alert-danger', notice: 'alert-info', warn: 'alert-warning' }[flash[:type]] end |
#flash_object ⇒ Object
16 17 18 |
# File 'app/helpers/writefully/flash_helper.rb', line 16 def flash_object flash[:object_type].classify.constantize.where(id: flash[:object_id]).first end |
#flash_path ⇒ Object
20 21 22 |
# File 'app/helpers/writefully/flash_helper.rb', line 20 def flash_path File.join((flash[:namespace] || nil), controller_name, 'flash', flash[:from].to_s, flash[:type].to_s) end |
#flash_values_count ⇒ Object
12 13 14 |
# File 'app/helpers/writefully/flash_helper.rb', line 12 def flash_values_count action_name == "create" ? 3 : flash.keys.count end |
#render_flash ⇒ Object
3 4 5 |
# File 'app/helpers/writefully/flash_helper.rb', line 3 def render_flash render 'flash' if can_flash? end |