ShowMessage
Installation
Add this line to your application's Gemfile:
gem 'show_message'
And then execute:
$ bundle
Or install it yourself as:
$ gem install
Usage
Add this code where you want your messages to be shown. You will need to create some styles for the message box. See further down for the HTML this outputs so you know how to style it.
<%= show_message %>
Now, set a message in your controller. You can use :error, :success, :myCoolMessage or :whatever. You get the point. The only thing you should not use is and "_". Read on to see why.
Also, it you can set a single message as a String or multiple as an Array
class MyController
def test_function
flash[:success] = "Some Success Message"
end
end
Now, when using remote forms I came across the issue where I would have multiple show_message helpers on the same page. This led to some issues so I added the ability to set an id on show_message
<%= show_message(id: :create_object) %>
There is a slight twist to setting the flash now. I use an "_" to find what I call "scoped" messages.
class MyController
def test_function
flash[:error_create_object] = "Some Error Message"
end
end
Lastly, I found the need to insert a margin below the message sometimes.
<%= show_message(space: 10) %>
<!-- will insert a 10px margin below -->
show_message - HTML Output
Below is HTML that show_message will output. You will need to create a few styles to make yours look nice. I left it free of styles since I was using Zurb Foundation. I also figured most people would want to style their own anyway.
<div class="alert-box [the flash symbol will be here to]">
<div class="message">
Message gets outputed here.
</div>
</div>
Contributing
If anyone has any suggestions on a better way to do the "scoped" messages or anything for that matter, feel free to submit a pull request.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request

