Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Non-expiring flash
# Visit:
# /main/set_flash
# /main/show_no_flash (as many times as you like)
# /main/show_flash ... and it shows the flash message
# (Rails 4.1.8, Ruby 2.1.1)
# app/controllers/main_controller.rb
class MainController < ApplicationController
def show_flash
render inline: flash[:notice] || "Flash is blank!"
end
def set_flash
flash[:notice] = "FLASH!"
render inline: "Nothing to see here"
end
def show_no_flash
render inline: "Nothing to see here"
end
end
# config/routes.rb
Rails.application.routes.draw do
get 'main/set_flash'
get 'main/show_flash'
get 'main/show_no_flash'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment