Skip to content

Instantly share code, notes, and snippets.

@anthonyjsmith
Created November 25, 2014 16:39
Show Gist options
  • Save anthonyjsmith/53fccd30ee0873b06c8b to your computer and use it in GitHub Desktop.
Save anthonyjsmith/53fccd30ee0873b06c8b to your computer and use it in GitHub Desktop.
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