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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:49:01+00:00 2026-05-29T05:49:01+00:00

I am starting to learn ruby on rails, like it so far. But I

  • 0

I am starting to learn ruby on rails, like it so far. But I have a hard time wrapping my head around those flash-sessions.

I would rather have it working something like:

flash[:alert] << "first alert message" 
flash[:alert] << "second alert message"

But, it doesn’t work (edit: since flash[:alert] isn’t an array). A solution would be to initiate flash[:alert] as an empty array in some kind of construct, i tried it in a before_filter but didn’t get it to work.

Any ideas?

Edit:
As I’ve written in some comments. What i am trying to do is find a place to convert flash[:alert] to an array. In some sort of construct. If i do it before i call flash[:alert] i have to know when i will be doing it the first time so i won’t overwrite anything I allready have in it.

  • 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-29T05:49:02+00:00Added an answer on May 29, 2026 at 5:49 am

    You could write a helper method in your application controller. For example, like this:

    class ApplicationController
    
      def add_to_flash_array key, value
        # set empty array as default value
        flash[key] ||= [] 
    
        if flash[key].is_a? Array
          flash[key] << value
        else # somebody set a value from underneath this method, enter panic mode
          raise "flash['#{key}'] is not an array!"
        end
      end
    end
    
    # usage
    
    add_to_flash_array :alert, 'Message 1'
    add_to_flash_array :alert, 'Message 2'
    

    Then in your view loop over flash[:alert] and build your markup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just starting to learn Ruby on Rails and have a newbie question
Just starting to learn Ruby on Rails. I'm using RoR 3. I have read
I'm starting to learn Ruby on Rails but this question is bugging me. As
I'm starting right from the beginning with Ruby to learn the ropes but have
I'm starting to learn Python and I've come across generator functions, those that have
I'm just starting to learn Ruby and have a problem with encoding; require 'rubygems'
I am just starting to learn Ruby (to eventually move to RoR), but I
i'm starting to learn ruby on rails using this guide : getting_started , i
I am just starting to learn javascript, so I don't have the skills to
I'm starting to learn Excel Programming and have been doing the development in Excel

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.