Rack::EnvNotifier
Lightweight middleware notifications
Have you ever done something like the code bellow?
<!-- html content here... -->
<body>
<% if Rails.env.development? %>
<div style="position: fixed; top: 0; right: 0; left: 0;">Development mode</div>
<% end %>
<!-- html content here... -->
Well, I did it a lot until I made a super lightweight gem that hooks into the Rack::Middleware and does the same thing.
To use Rack::EnvNotifier all you have to do is add gem 'rack-env-notifier'
into the Gemfile.
And after a quick $ bundle
run you're good to go and setup the initializer.
A sample Rails initialiser may look like this:
if Rails.env.development?
Rack::EnvNotifier.notify = true
Rack::EnvNotifier.message = 'Dev'
end
Extra features:
It can hook up on any statement that returns true
or false
.
The notification message and the CSS can also be easily customised.
You can read more here.
Happy further coding!
Written by Catalin Ilinca
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#