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 6920159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:06:44+00:00 2026-05-27T10:06:44+00:00

I would like to have different style for different type of flash messages: error,

  • 0

I would like to have different style for different type of flash messages: error, notice, success.
How would I identify the type of flash messages passed to my view?

In my controller, I have:

flash[:error] = "Access denied."

In my application.html.haml, I have:

  - if not flash.empty?
    - flash.each do |key, value|
      %div{:class => "alert-message #{key}"}= value

Thank you.

  • 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-27T10:06:45+00:00Added an answer on May 27, 2026 at 10:06 am

    flash is essentially based on a hash. Each kind of flash message is just the value associated with a symbol key for that type. So flash[:error] is for error messages, flash[:notice] and flash[:success] for their key types. You can even define your own types (just using any symbol). And you can have any number of keys set at once (so you can for example set a flash[:notice] and flash[:error] in the same request).

    In your example, this is creating a div with the class alert-message #{key}. So, for example, if you set a flash[:notice] the output would be:

    <div class="alert-message notice">Notice message</div>
    

    And it will print one for each type you set. So if the request set flash[:error] = 'something went terribly wrong' and flash[:notice] = 'take a look around', you’d get this html from that template:

    <div class="alert-message error">something went terribly wrong</div>
    <div class="alert-message notice">take a look around</div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have different applications under the same domain using Heroku. Because
I would like to have a form that can submit to two different action
I have two different tables, lead and click. I would like to query MySQL
I have two different .Net projects, hosted on github. I would like to create
I would like to track how many surveys have been done by different departments
I have a lot of different UserControls and would like to maintain consistent UI
I have an Java applications which I would like to run with different values
I have seen this problem arise in many different circumstances and would like to
I have code like this: <div class=ui-widget> <ul style=list-style-type: none; padding-left: 0; id=menuList> <li>
I have two strings and would like to display the difference between them. For

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.