Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
mutiple messages by flash
8 Posts
mutiple messages by flash

I would handle this differently.

flash[:welcome] = "Welcome to my site!" flash[:notice] = "I am happy to have you!"

Then in the view do:

key %>

That will not just iterate your flash messages, but you can style each type with css. It will output divs with the flash :key as the class name.

Person
Sr. Ruby & Rails Consultant For Hire
Sign In To Rate Post

Thanks a lot Balaji. It worked well.

--Balu.

Chris ur absolutely right nl2br is a PHP fn , i just messed it up :(

Instead of using nl2br Try this boss flash[:notice].gsub(/\n/, "break")

( BR tag is parsed by the text editor so i have used the text 'break', please replace it with html br tag )

Person
Forum Rating: 100
Sign In To Rate Post

Thanks for your inputs.

I have tried both the ideas, but couldn't reached the expected.

Thanks, Balu.

Try this in your view

Person
Forum Rating: 100
Sign In To Rate Post

Hi Balaji,

Thank you very much for your reply. it worked for me. but the messages are not displaying in line by line. They are displaying as a continuous string.

I did the same as you suggested.

In the view i am displaying the flash by the statement:

Please do the needful.

Thanks, Balu.

I am not very clear about your question. If you want to display combination of messages in the flash notice , you can just have an array to store all the flash messages you need and at the end just join them by a new line character and then assign it to the flash.

Like:

messages = Array.new messages << “Hi, welcome..” messages << “Hi, welcome..to my website.” .....

flash[:notice] = messages.join('\n')

Person
Forum Rating: 100
Sign In To Rate Post

Hi,

Could any one let me know how to setup the flash system available in Rails, to display mutiple messages at a time on the view.

flash[:notice] = "Hi, welcome.." flash[:notice] = "Hi, welcome..to my website."

i wanted these two messages displayed in the Next page.How it can be done?Please help me out.

Thanks Balu.

8 Posts
Login to add your message