Discussion Forums
- Topic List
- Most Recent Posts
- Sign In for more options
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.
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')
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.
Thanks for your inputs.
I have tried both the ideas, but couldn't reached the expected.
Thanks, 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 )
Thanks a lot Balaji. It worked well.
--Balu.
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.
