KangOnRails
KangOnRails

Reputation: 143

Ruby On Rails Flash.each creating curly brackets on page, not going away

I am currently taking a course on Ruby on Rails and it is going well, but when i get to doing a flash.each (code below) i keep getting {} showing up on my actual page, only when i delete the line of code does it go away.. I have not a clue why

<%= flash.each do |key, value| %> 
  <%= content_tag :div, value, class: "alert alert-#{key}" %>
<% end %>

That is the code that is in my Application.html.erb file they connect with this

class ContactsController < ApplicationController
  def new
    @contact = Contact.new
  end

  def create
    @contact = Contact.new(contact_params)

    if @contact.save
      flash[:success] = "Message Sent"
      redirect_to new_contact_path
    else 
      flash[:danger] = "Message not sent ID10T ERROR occured"
      redirect_to new_contact_path

    end
  end
end

The success and danger are bootstrap classes btw...

On top of the rouge {} just chilling on my page i get a {"success"=>"Message Sent"} appearing below my Message Sent notice... I am stumped and while i can live with it like that, I do not want to go half on my first rails app.. All help is appreciated.. I will link the website so you can see what I am talking about, I will leave the server running as long as i can, to see the {success => message} just fill out a fake name email and comment and click submit... Thanks so much

https://udemy-rails-coder-nohashkang.c9users.io/contacts/new

Upvotes: 1

Views: 583

Answers (1)

Holger Just
Holger Just

Reputation: 55803

<%= flash.each do |key, value| %> 

must be

<% flash.each do |key, value| %> 

Since you are not intending to output the return value of the each method, you have to get rid of the ERB output tag.

What you are seeing now in the output is the return value of this method which contains the internal Ruby structures of the flash values.

Upvotes: 3

Related Questions