title: Ruby on Rails 4.2.3 flash notice/alert on redirect_to not showing in view
body: <p>It's worth noting that this is my first Rails application. I have done quite a bit of reading on this but all the suggestions I've tried still do not work. In short, I'm using <code>gem 'devise', '~&gt; 3.5.1'</code> and the Rails flash notification component to notify a user when they are trying to edit a record in a model that they do not own. It is a simple Reviews application, allowing users that are logged in to submit a review, and if they created it, they can edit it, as well, but only if they created it. Here's what I've got so far.</p>
  
  <p><strong>reviews_controller.rb</strong></p>
  
  <pre><code>class ReviewsController &lt; ApplicationController
    before_action :set_review, only: [:show, :edit, :update, :destroy]
    before_filter :authenticate_user!, except: [:index, :show]
    # GET /reviews
    # GET /reviews.json
    def index
      @reviews = Review.all
    end
  
    # GET /reviews/1
    # GET /reviews/1.json
    def show
    end
  
    # GET /reviews/new
    def new
      #@review = Review.new
      @review = current_user.reviews.build
    end
  
    # GET /reviews/1/edit
    def edit
      @review = Review.find(params[:id])
      if current_user.id == @review.user_id
        # default action
      else
        #flash[:alert] = "You do not have permission to edit this Review."
        #redirect_to @review
        #flash.alert = "You do not have permission to edit this Review."
        #redirect_to @review
        redirect_to @review, alert: 'You do not have permission to edit this Review.'
        #redirect_to @review, :flash =&gt; { :alert =&gt; 'You do not have permission to edit this Review.' }
      end 
    end
  
    # POST /reviews
    # POST /reviews.json
    def create
      #@review = Review.new(review_params)
      @review = current_user.reviews.build(review_params)
  
      respond_to do |format|
        if @review.save
          format.html { redirect_to @review, notice: 'Review was successfully created.' }
          format.json { render :show, status: :created, location: @review }
        else
          format.html { render :new }
          format.json { render json: @review.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /reviews/1
    # PATCH/PUT /reviews/1.json
    def update
      @review = Review.find(params[:id])
      if current_user.id == @review.user_id
        respond_to do |format|
          if @review.update(review_params)
            format.html { redirect_to @review, notice: 'Review was successfully updated.' }
            format.json { render :show, status: :ok, location: @review }
          else
            format.html { render :edit }
            format.json { render json: @review.errors, status: :unprocessable_entity }
          end
        end
      else
        redirect_to @review, notice: 'You do not have permission to edit this Review.'
      end
    end
  
    # DELETE /reviews/1
    # DELETE /reviews/1.json
    def destroy
      @review.destroy
      respond_to do |format|
        format.html { redirect_to reviews_url, notice: 'Review was successfully destroyed.' }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_review
        @review = Review.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def review_params
        params.require(:review).permit(:title, :content)
      end
  end
  </code></pre>
  
  <p>if you look under <code>def edit</code> in the above file, you can see I've tried a few things to pass the flash notification. I cannot get it to appear no matter what I try. Here's the show view code.</p>
  
  <p><strong>reviews/show.html.erb</strong></p>
  
  <pre><code>&lt;p id="notice"&gt;&lt;%= notice %&gt;&lt;/p&gt;
  &lt;p id="alert"&gt;&lt;%= alert %&gt;&lt;/p&gt;
  &lt;% flash.each do |name, msg| %&gt;
    &lt;% content_tag(:div, msg, class: "alert alert-#{name}") %&gt;
  &lt;% end %&gt;
  
  &lt;p&gt;
    &lt;strong&gt;Title:&lt;/strong&gt;
    &lt;%= @review.title %&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
    &lt;strong&gt;Content:&lt;/strong&gt;
    &lt;%= @review.content %&gt;
  &lt;/p&gt;
  
  &lt;%= link_to 'Edit', edit_review_path(@review) %&gt; |
  &lt;%= link_to 'Back', reviews_path %&gt;
  </code></pre>
  
  <p>It will show up in the view with <code>&lt;p id="notice"&gt;&lt;%= notice %&gt;&lt;/p&gt;</code> or the <code>&lt;p id="alert"&gt;&lt;%= alert %&gt;&lt;/p&gt;</code> code but not within the <code>flash.each</code> loop, which is what I'm trying to fix. I'd like to pass the message and message-type as indicated in the flash.each loop. As far as I can tell, this is pretty standard way of displaying flash messages in a view.</p>
  
  <p>Here is my <strong>Gemfile</strong> in case you need it.</p>
  
  <pre><code>source 'https://rubygems.org'
  
  ruby '2.1.5'
  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
  gem 'rails', '4.2.3'
  # Use sqlite3 as the database for Active Record
  gem 'sqlite3'
  # Use SCSS for stylesheets
  gem 'sass-rails', '~&gt; 5.0'
  # Use Uglifier as compressor for JavaScript assets
  gem 'uglifier', '&gt;= 1.3.0'
  # Use CoffeeScript for .coffee assets and views
  gem 'coffee-rails', '~&gt; 4.1.0'
  # See https://github.com/rails/execjs#readme for more supported runtimes
  # gem 'therubyracer', platforms: :ruby
  gem 'devise', '~&gt; 3.5.1'
  # Use jquery as the JavaScript library
  gem 'jquery-rails'
  # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
  gem 'turbolinks'
  # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
  gem 'jbuilder', '~&gt; 2.0'
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', '~&gt; 0.4.0', group: :doc
  
  # Use ActiveModel has_secure_password
  # gem 'bcrypt', '~&gt; 3.1.7'
  
  # Use Unicorn as the app server
  # gem 'unicorn'
  
  # Use Capistrano for deployment
  # gem 'capistrano-rails', group: :development
  
  group :development, :test do
    # Call 'byebug' anywhere in the code to stop execution and get a debugger console
    gem 'byebug'
  
    # Access an IRB console on exception pages or by using &lt;%= console %&gt; in views
    gem 'web-console', '~&gt; 2.0'
  
    # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
    gem 'spring'
  end
  </code></pre>
  
  <p>What's going on here? What am I missing? Thanks so much in advance!</p>