Skip to content

Instantly share code, notes, and snippets.

@onemanstartup
Created November 16, 2014 07:34
Show Gist options
  • Save onemanstartup/c6248bc88a0ab9fe502b to your computer and use it in GitHub Desktop.
Save onemanstartup/c6248bc88a0ab9fe502b to your computer and use it in GitHub Desktop.

Revisions

  1. onemanstartup created this gist Nov 16, 2014.
    40 changes: 40 additions & 0 deletions flashes.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    def flash_success(message = nil, opts = {})
    if message
    flash[:success] = message
    else
    flash[:success] = translate '.flash.success_html'.freeze, view_assigns.symbolize_keys.merge(opts).merge(default: :"flash.default.success")
    end
    end

    def flash_error(message = nil, opts = {})
    if message
    flash[:error] = message
    else
    flash[:error] = t '.flash.error_html'.freeze, view_assigns.symbolize_keys.merge(opts).merge(default: :"flash.default.error")
    end
    end

    def flash_custom(type, message = nil, opts = {})
    if message
    flash[:type] = message
    else
    flash[:type] = t ".flash.#{type}_html".freeze, view_assigns.symbolize_keys.merge(opts).merge(default: :"flash.default.#{type}")
    end
    end

    ru:
    flash:
    default:
    success: 'Действие выполнено успешно'
    error: 'Действие было выполнено с ошибкой'
    feedbacks:
    new:
    flash:
    success_html: "hello %{email}"


    flash_error 'hello', email: current_user.email
    flash_error 'hello'
    flash_success
    flash_custom :notice
    flash_custom :notice, 'hello'