mkhairi / materialize-sass

Materializecss rubygem for Rails Asset Pipeline / Sprockets
http://materialize.labs.my/
MIT License
805 stars 243 forks source link

I have a project with make a Toasts , how do make? #132

Closed marcosvicente closed 6 years ago

marcosvicente commented 7 years ago

I want to include with notice, that I am using the gem device . <%= notice %> How do make a toasts. Thanks for help.

mikewagz commented 7 years ago

I use this in my application.haml:

  :javascript
      var toastNoticeContent = "#{notice}";
      var toastAlertContent = "#{alert}";
      var toastErrorContent = "#{error}";

Then, in a JS file loaded on every request:

  if(toastNoticeContent != ""){
    Materialize.toast(toastNoticeContent, 6000)
  }
  if(toastAlertContent != ""){
    Materialize.toast(toastAlertContent, 6000, "alert")
  }
  if(toastErrorContent != ""){
    Materialize.toast(toastErrorContent, 10000, "error")
  }
rubendinho commented 7 years ago

@mikewagz - out of curiosity, how are you serving up that JS file on every request?

mikewagz commented 7 years ago

@rubendinho - I use a common.js file that is loaded from my application.js file like this:

//= require jquery
//= require jquery_ujs
// .. other libraries, etc.
//= require common
//= require_tree ./components
//= require_tree ./pages
mkhairi commented 6 years ago

toaster helper now available at master branch :)