Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6665787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:45:36+00:00 2026-05-26T02:45:36+00:00

So what I am trying to do is to apply a different class to

  • 0

So what I am trying to do is to apply a different class to the div containing the flash message depending on the type of flash message (i.e. error, notice, etc.).

I have this in my application.html.erb:

 <%- flash.each do |name, msg| -%>
        <% if name = "error" %>
            <%= content_tag :div, msg, :id => "flash_#{name}", :class => "alert-message error" %>
        <% elsif name = "notice" %>
            <%= content_tag :div, msg, :id => "flash_#{name}", :class => "alert-message success" %>
        <% elsif name = "warning" %>
            <%= content_tag :div, msg, :id => "flash_#{name}", :class => "alert-message warning" %>
        <% end %>
      <%- end -%>

But, it is always outputting a div with id=flash_error.

Why is that?

Update 1:

If I change the equality checks to be ==, it seems to completely skip over that portion of the if statement.

 <%- flash.each do |name, msg| -%>
        <% if name == "error" %>
            <%= content_tag :div, msg, :id => "flash_#{name}", :class => "alert-message error" %>
        <% elsif name = "notice" %>
            <%= content_tag :div, msg, :id => "flash_#{name}", :class => "alert-message success" %>
        <% elsif name == "warning" %>
            <%= content_tag :div, msg, :id => "flash_#{name}", :class => "alert-message warning" %>
        <% end %>
      <%- end -%>

If you notice, in the code above, I have == in for error and warning and I have = for notice. Well, in this case it actually outputs the notice div like I want it to. It seems that when I do a check for ="error" it exits the conditional altogether, regardless of whether or not the check was right. But once I add == it doesn’t even do the check it seems. Very bizarre!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:45:36+00:00Added an answer on May 26, 2026 at 2:45 am

    Could it be because you are not checking for equality?

    Not a check for equality

    <% if name = "error" %>
    

    A check for equality

    <% if name == "error" %>
    

    It could also be that you are checking for a string. The flash hash is indexed by symbols.

    Try

    <% if name == :error %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to figure this out: i have some html and php: <div
I am trying to apply css rules to tr elements depending on what class
Im trying to apply different background color to even and odd items in a
I'm trying to apply the MVVM design pattern to a diagramming application. In this
I'm really lost on this case. I am trying to apply a custom MVC
I am trying to apply styles to HTML tags dynamically by reading in the
I'm trying to apply a transform to a 3D object in a STL File
I am trying to apply css on my html.dropdownlist with a regular html select
I am trying to apply conditional formatting of certain table cells in my ReportViewer
I'm trying to apply a DataTrigger to a Button and it depends on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.