Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alert-messages-for-hanami

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alert-messages-for-hanami

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

AlertMessages for Hanami

A helper to add alert messages (including flash ... aah! messages) to an Hanami application.

Status

Gem Version Build Status Coverage Status

Installation

Add this line to your application's Gemfile:

gem 'alert-messages-for-hanami', '~> 0.1'

Usage

Configuration

In your application.rb include

require 'alert-messages-for-hanami'

and then

# Configure the code that will yield each time Admin::Action is included
# This is useful for sharing common functionality
#
# See: http://www.rubydoc.info/gems/hanami-controller#Configuration
controller.prepare do
	# include MyAuthentication # included in all the actions
	# before :authenticate!    # run an authentication before callback

	include CabezaDeTermo::AlertMessages::Behaviour
end

Adding messages in your actions

To add a message to show in the current page, do

module Web::Controllers::Login
	class Create
		include Web::Action

		def call(params)
			alert_messages[:info] << 'You know nothing, John Snow'
		end
	end
end

To add a message to show in next request or redirect, first enable sessions in your application and then you can do

module Web::Controllers::Login
	class Create
		def call(params)
			alert_messages.flash_at(:info) << 'Flash! aah ... king of the immmmpossible'
		end
	end
end

Showing messages

In your template do something like

- alert_messages[:success].each do |success_message|
	.alert.alert-success role="alert"
		= success_message

- alert_messages[:info].each do |info_message|
	.alert.alert-info role="alert"
		= info_message

- alert_messages[:warnings].each do |warning_message|
	.alert.alert-warning role="alert"
		= warning_message

- alert_messages[:errors].each do |error_message|
	.alert.alert-danger role="alert"
		= error_message

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/cabeza-de-termo/alert-messages.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 17 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc