toastr_rails是一个基于toastr的gem。toastr的demo
用法直接看usage就好了。
- gem "toastr_rails"
- 在
assets/javascripts/application.js中加入//= require toastr_rails - 在
assets/stylesheets/application.js中加入*= require toastr_rails - 在
views/layouts/application.htm.erb中加入<%= render 'toastr_rails/flash' %> - 用
flash[:info] = "hi,there"调用即可
也可以修改一些options
- 在
assets/javascripts/application.js
toastr.options = {
"closeButton": false,
"debug": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-top-right",
"preventDuplicates": false,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
更多详细的options可以在demo中调试,然后直接复制过来。
- 在
assets/stylesheets/application.js中也可以调整样式,比如这样
#toast-container{
top: 50px;
}
当然,也可以直接把toastr引入到项目中。