supportoranges
supportoranges

Reputation: 1

ActiveRecord producing double messages

this code generated by scaffold ends up printing the same message twice and i can't get it to stop.

  def update
    respond_to do |format|
      if @indi.update(indi_params)
        puts("message about to be shown to us by the system")
        format.html { redirect_to @indi, notice: 'Indi was successfully updated.' }
        format.json { render :show, status: :ok, location: @indi }
      else
        format.html { render :edit }
        format.json { render json: @indi.errors, status: :unprocessable_entity }
      end
    end
  end

it prints the success message twice in the web page.

Upvotes: 0

Views: 149

Answers (1)

kiddorails
kiddorails

Reputation: 13014

To close the question:

Problem was in double rendering in the layout as well as view. He had:

<body>
  <% if notice %>
    <p class="alert alert-success"><%= notice %></p>
  <% end %>
  <% if alert %>
    <p class="alert alert-danger"><%= alert %></p>
  <% end %> 
  <%= yield %> 
</body>

and in top of show.html.erb:

<p id="notice"><%= notice %></p>

This resulted in double display of notice. Fix was to simply remove from show.html.erb and to have that in layout. Layout enables such code to be re-used

Upvotes: 1

Related Questions