5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails 5のflashにmaterializeのtoastを使用する

Last updated at Posted at 2018-10-08

toastって?

ユーザーに控えめな注意を促すUIです。トースターから出てくるように、ポンっと下から出ます。
ezgif-5-306791934ad7.gif

本家の説明および実際のサンプル(英語。オプションやらプロパティの詳細も載ってます)

設定

Gemfile

gem 'materialize-sass', '~> 1.0.0.rc2'
app/assets/javascripts/application.js

// 省略
//= require materialize
app/assets/stylesheets/application.scss

// 省略
@import "materialize";
app/views/layouts/application.html.haml

  -# 省略
  %body
    = render("layouts/toast")
    = yield
app/views/layouts/_toast.html.haml

- flash.each do |type, msg|
  -# 色についてはhttps://materializecss.com/color.htmlを参照
  - color = 'light-blue lighten-3' if type == 'notice'
  - color = 'red lighten-1' if type == 'alert'

  = javascript_tag "M.toast({html: '#{msg}',
                             classes: '#{color}',
                             displayLength: 2000})"
5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?