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.
flashes
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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment