开发者

displaying flash messages

I开发者_如何学JAVA am quite new to rails...

I am having an issue with displaying of flash messages...

Am displaying it in views as well as application.html.erb (layout file)

in the view i just have

flash[:notice]

and in the application.html.erb I have

flash.each do |name, msg| 
content_tag :div, msg, :id => "flash_#{name}"
end

I want to display all the flash messages at once, currently with the above structure, it displays in two different locations... I found a post very similar to what I wanted to do... This might explain it clearly : http://pupeno.com/blog/ensuring-the-displaying-of-flash-messages-in-ruby-on-rails/ The solution provided here din't work...

any help?


both your partials and the layout file (application.html.erb) are part of the view. so, if you are putting a way to output flash messages in both places, then you will see it twice since they both get rendered.

The author of the link you added also did some checking of a boolean instance variable to ensure that the messages are only displayed once. I don't see you doing this in the code you posted which may explain why you aren't seeing the same results. You could add the boolean checking (what was done with @messages_rendered) or you could put the flash messages in only one place (layout file or a view partial). I'm not sure exactly what you want it to end up looking like, so you might just need to play around with the different options and see what you like.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜