Sha256: e3de6bab7d6fcd65f3ebec13ec32ceb30bfe997f2e3c5193b96202e50c8c1b5f

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

module BootstrapFlashMessages
  module FlashMessages
    def redirect_to(options = {}, response_status_and_flash = {})
      messages = response_status_and_flash[:flash]
      if messages && (messages.is_a?(Symbol) || messages.is_a?(Array))
        flashes = {}
        locals = response_status_and_flash[:locals]
        if messages.is_a?(Array)
          messages.each do |key|
            flashes[key] = flash_messages(key, locals)
          end
        else
          flashes[messages] = flash_messages(messages, locals)
        end
        response_status_and_flash.delete(:locals)
        response_status_and_flash[:flash] = flashes
      end
      super(options, response_status_and_flash)
    end

  private

    def flash!(*args)
      options = args.extract_options!
      args.each do |key|
        flash[key] = flash_messages(key, options[:locals])
      end
    end

    def flash_now!(*args)
      options = args.extract_options!
      args.each do |key|
        flash.now[key] = flash_messages(key, options[:locals])
      end
    end

    def flash_messages(key, *args)
      i18n_key = "flash_messages.#{params[:controller]}.#{params[:action]}.#{key}"
      options = args.extract_options!
      options[:default] = i18n_key.to_sym
      I18n.t(i18n_key.gsub(/\//, "."), options).html_safe
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bootstrap_flash_messages-0.0.7 lib/bootstrap_flash_messages/flash_messages.rb
bootstrap_flash_messages-0.0.6 lib/bootstrap_flash_messages/flash_messages.rb
bootstrap_flash_messages-0.0.5 lib/bootstrap_flash_messages/flash_messages.rb