$ rails new club
$ cd club
$ rails g scaffold member name age:integer
$ rake db:create db:migrate && rails s
What are flash messages?
Slide 3
Slide 3 text
$ rails new club
$ cd club
$ rails g scaffold member name age:integer
$ rake db:create db:migrate && rails s
What are flash messages?
Slide 4
Slide 4 text
$ rails new club
$ cd club
$ rails g scaffold member name age:integer
$ rake db:create db:migrate && rails s
What are flash messages?
Slide 5
Slide 5 text
$ rails new club
$ cd club
$ rails g scaffold member name age:integer
$ rake db:create db:migrate && rails s
What are flash messages?
Slide 6
Slide 6 text
$ rails new club
$ cd club
$ rails g scaffold member name age:integer
$ rake db:create db:migrate && rails s
What are flash messages?
Slide 7
Slide 7 text
$ rails new club
$ cd club
$ rails g scaffold member name age:integer
$ rake db:create db:migrate && rails s
What are flash messages?
Slide 8
Slide 8 text
$ rails new club
$ cd club
$ rails g scaffold member name age:integer
$ rake db:create db:migrate && rails s
What are flash messages?
Slide 9
Slide 9 text
$ rails new club
$ cd club
$ rails g scaffold member name age:integer
$ rake db:create db:migrate && rails s
What are flash messages?
Slide 10
Slide 10 text
$ rails new club
$ cd club
$ rails g scaffold member name age:integer
$ rake db:create db:migrate && rails s
What are flash messages?
Slide 11
Slide 11 text
$ rails new club
$ cd club
$ rails g scaffold member name age:integer
$ rake db:create db:migrate && rails s
What are flash messages?
Slide 12
Slide 12 text
$ rails new club
$ cd club
$ rails g scaffold member name age:integer
$ rake db:create db:migrate && rails s
What are flash messages?
Slide 13
Slide 13 text
$ rails new club
$ cd club
$ rails g scaffold member name age:integer
$ rake db:create db:migrate && rails s
What are flash messages?
Slide 14
Slide 14 text
$ rails new club
$ cd club
$ rails g scaffold member name age:integer
$ rake db:create db:migrate && rails s
What are flash messages?
Slide 15
Slide 15 text
What bad can flash messages do?
1.Disappear after reload
2.Distort the attention of the user
3.Are target of designers’ minimalism
4.Are not mobile-friendly
def create
@member = Member.new(member_params)
respond_to do |format|
if @member.save
format.html { redirect_to @member,
notice: 'Member was successfully created.' }
format.json { render :show, status: :created} […]
Slide 16
Slide 16 text
What bad can flash messages do?
1.Disappear after reload
2.Distort the attention of the user
3.Are target of designers’ minimalism
4.Are not mobile-friendly
def create
@member = Member.new(member_params)
respond_to do |format|
if @member.save
format.html { redirect_to @member,
notice: 'Member was successfully created.' }
format.json { render :show, status: :created} […]
Slide 17
Slide 17 text
What bad can flash messages do?
1.Disappear after reload
2.Distort the attention of the user
3.Are target of designers’ minimalism
4.Are not mobile-friendly
5.Require hacks to work with Javascript
6.Require I18N in the controller
7.Are not cache-friendly
def create
@member = Member.new(member_params)
respond_to do |format|
if @member.save
format.html { redirect_to @member,
notice: 'Member was successfully created.' }
format.json { render :show, status: :created} […]
Slide 18
Slide 18 text
Symptoms of a problem
We are not “sure” of the value of the
information, so we choose a middle-
ground of “showing it only once”.
By doing this, we go against the REST
paradigms of individual resources and
nullipotence of the GET method.
Slide 19
Slide 19 text
How to avoid flash messages
# On successful create
redirect_to @member,
notice: 'Member was successfully created.'
Slide 20
Slide 20 text
How to avoid flash messages
# On successful create
redirect_to @member,
notice: 'Member was successfully created.'
Slide 21
Slide 21 text
How to avoid flash messages
# On successful update
redirect_to @member,
notice: 'Member was successfully updated.'
Slide 22
Slide 22 text
How to avoid flash messages
# On successful update
redirect_to @member,
notice: 'Member was successfully updated.'
Slide 23
Slide 23 text
How to avoid flash messages
# On successful update
redirect_to @member,
notice: 'Member was successfully updated.'
Slide 24
Slide 24 text
How to avoid flash messages
# On successful destroy (from index)
redirect_to members_url,
notice: 'Member was successfully destroyed.'
Slide 25
Slide 25 text
How to avoid flash messages
# On successful destroy (from index)
redirect_to members_url,
notice: 'Member was successfully destroyed.'
Slide 26
Slide 26 text
How to avoid flash messages
# On successful destroy (from index)
redirect_to members_url,
notice: 'Member was successfully destroyed.'
Slide 27
Slide 27 text
How to avoid flash messages
# On successful destroy (from show)
redirect_to members_url,
notice: 'Member was successfully destroyed.’
Slide 28
Slide 28 text
How to avoid flash messages
# On successful destroy (from show)
redirect_to members_url,
notice: 'Member was successfully destroyed.’
Slide 29
Slide 29 text
How to avoid flash messages
# On successful destroy (from show)
redirect_to members_url,
notice: 'Member was successfully destroyed.’
redirect_to :back
Slide 30
Slide 30 text
How to avoid flash messages
# On successful destroy (from show)
redirect_to members_url,
notice: 'Member was successfully destroyed.’
redirect_to :back
Slide 31
Slide 31 text
How to avoid flash messages
# db/migrate/20160114174326_add_status_to_member.rb
class AddStatusToMember < ActiveRecord::Migration
def change
add_column :members, :status, :integer,
default: 0, null: false
end
end
# app/models/member.rb
class Member < ActiveRecord::Base
enum status: %i(active inactive)
end
Slide 32
Slide 32 text
How to avoid flash messages
# app/controllers/members_controller.rb
class MembersController < ApplicationController
def destroy
@member.destroy
end
def index
@members = Member.all
end
def show
end
end
@member.inactive!
Member.active
render @member.status
Slide 33
Slide 33 text
How to avoid flash messages
# app/views/members/active.html.erb
Last updated:
<%= time_ago_in_words @member.updated_at %> ago
Name:
[…] # it’s just show.html.erb renamed
# app/views/members/inactive.html.erb
This user is no longer active.
<%= link_to 'Back', members_path %>
Slide 34
Slide 34 text
How to avoid flash messages
# On successful destroy (from show)
redirect_to members_url,
notice: 'Member was successfully destroyed.’
redirect_to :back
Slide 35
Slide 35 text
How to avoid flash messages
# On successful destroy (from show)
redirect_to members_url,
notice: 'Member was successfully destroyed.’
redirect_to :back
Slide 36
Slide 36 text
Summing up
We give “for granted” flash messages in
Rails, but reasoning about them can
lead to a better user experience.
The real minimalism is not to hide
flash messages, but to remove the
reasons why we need them.
Slide 37
Slide 37 text
How to resist the temptation
# config/application.rb
module Club
class Application < Rails::Application
config.middleware.delete ActionDispatch::Flash
end
end
Thanks! !
speakerdeck.com/claudiob