Skip to content

Files

Latest commit

 

History

History
32 lines (24 loc) · 677 Bytes

Rails-ActionControllerFlashBeforeRender.md

File metadata and controls

32 lines (24 loc) · 677 Bytes

Pattern: Use of flash before render in Rails controller

Issue: -

Description

Using flash assignment before render in Rails controllers will persist the message for too long.

Examples

# bad
class HomeController < ApplicationController
  def create
    flash[:alert] = "msg"
    render :index
  end
end

# good
class HomeController < ApplicationController
  def create
    flash.now[:alert] = "msg"
    render :index
  end
end

Further Reading