When you sign in or log out, you can display a message such as "Login." "Logout." At the top of the screen. If you use devise, the message to be displayed at login etc. is automatically stored in the "flash object".
Within the flash object, multiple messages are stored in "key" and "value" formats like a hash.
Place the view file _notifications.html.haml for flash messages in views / layouts and load it with render in the body of application.html.haml.
ruby:_notifications.html.haml
.Notification
- flash.each do |key, value|
= content_tag :div, value, class: key
ruby:application.html.haml
%body
= render 'layouts/notifications'
= yield
By default, flash creates two keys, "notice" and "alert". Apply style to each
stylesheets/modules/_flash.scss
.Notification {
.notice {
background-color: #38AEF0;
color: #fff;
text-align: center;
}
.alert {
background-color: #F35500;
color: #fff;
text-align: center;
}
}
Finally, edit application.scss and load the created configuration file
app/assets/stylesheets/application.scss
@import "modules/flash";
First, create a file for Japanese localization Create new files named "devise.ja.yml" and "ja.yml" in the "config / locales" folder.
The contents are posted on the following sites, so copy and paste the entire contents and save. devise.ja.yml ja.yml
Next, let's edit application.rb and change the language setting.
config/application.rb
class Application < Rails::Application
#~abridgement~
config.i18n.default_locale = :ja
end
end
Recommended Posts