Sha256: 4c99d4227e9f6bfc8b78725b0aab9afe96e3361aad0aad50ebd06fe9d329832a

Contents?: true

Size: 788 Bytes

Versions: 26

Compression:

Stored size: 788 Bytes

Contents

module Writefully
  module FlashHelper
    def render_flash
      render 'flash' if can_flash?
    end

    def can_flash?
      flash.keys.sort == [:from, :object_id, :object_type, :type] and \
      flash.to_hash.values.compact.count == flash_values_count
    end

    def flash_values_count
      action_name == "create" ? 3 : flash.keys.count
    end

    def flash_object
      flash[:object_type].classify.constantize.where(id: flash[:object_id]).first
    end

    def flash_path
      File.join((flash[:namespace] || nil), controller_name, 'flash', flash[:from].to_s, flash[:type].to_s)
    end

    def flash_color
      { success: 'alert-success',
        error:   'alert-danger',
        notice:  'alert-info',
        warn:    'alert-warning' }[flash[:type]]
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
writefully-0.8.2 app/helpers/writefully/flash_helper.rb
writefully-0.8.1 app/helpers/writefully/flash_helper.rb
writefully-0.8.0 app/helpers/writefully/flash_helper.rb
writefully-0.7.1 app/helpers/writefully/flash_helper.rb
writefully-0.6.12 app/helpers/writefully/flash_helper.rb
writefully-0.6.11 app/helpers/writefully/flash_helper.rb
writefully-0.6.10 app/helpers/writefully/flash_helper.rb
writefully-0.6.9 app/helpers/writefully/flash_helper.rb
writefully-0.6.7 app/helpers/writefully/flash_helper.rb
writefully-0.6.6 app/helpers/writefully/flash_helper.rb
writefully-0.6.5 app/helpers/writefully/flash_helper.rb
writefully-0.6.4 app/helpers/writefully/flash_helper.rb
writefully-0.6.3 app/helpers/writefully/flash_helper.rb
writefully-0.6.2 app/helpers/writefully/flash_helper.rb
writefully-0.5.1 app/helpers/writefully/flash_helper.rb
writefully-0.5.0 app/helpers/writefully/flash_helper.rb
writefully-0.4.10 app/helpers/writefully/flash_helper.rb
writefully-0.4.8 app/helpers/writefully/flash_helper.rb
writefully-0.4.7 app/helpers/writefully/flash_helper.rb
writefully-0.4.6 app/helpers/writefully/flash_helper.rb