Alert Message
This is a simple gem for alerts messages.
Installation
Add to your Gemfile:
gem 'alert_message'
Then run:
$ bundle install
Run install script:
$ rails g alert_message:install
Add styles in app/assets/application.css
*= require alert_message
** For less than Rails 6 ** Add scripts in app/assets/application.js
//= require alert_message
For greater than Rails 6 add in app\javascript\packs\application.js
document.addEventListener('DOMContentLoaded', () => {
let alertMessage = document.getElementById('alert');
alertMessage.classList.add('alert-message--visible');
setTimeout((() => {
alertMessage.classList.remove('alert-message--visible');
}), 10000);
alertMessage.addEventListener('click', () => {
alertMessage.classList.remove('alert-message--visible');
});
});
How to use
Add in app/views/layouts/application.html.erb
<%= render "layouts/alerts" %>
To show your alerts, use:
flash[:error] = "YOUR MESSAGE"
flash[:notice] = "YOUR MESSAGE"
flash[:success] = "YOUR MESSAGE"
Example
class HomeController < ApplicationController
def index
flash[:error] = "YOUR MESSAGE"
end
end
Run testes
in progress
Contributing
Welcome to contribute
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
License
MIT License. Copyright 2014 Luiz Picolo. http://www.luizpicolo.com.br