Just curious how others render flash[:notice] and others in their views... Most Rails devs I see do something like this (overly simplified example) (application.html.erb) ... <% if flash[:notice].blaink? %> <div id="notice"> <%= flash[:notice] %> </div> <% end %> <div id="main"> <%=yield %> </div> .... Of course, this puts the flash above the main page content (your views.) I''ve noticed a few times that the notifications aren''t noticeable, no matter how much you style them. So, my question is, what do others do? Place the flash output in every view rather than in the layouts? Do you use JavaScript to move the div to a new location in the DOM? Thanks for your input! It should be neat to see different solutions. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Here''s a nice trick I use. I have the following in application_helper.rb: [code] def flash_div(*keys) visual_effect(:fade, :flashdiv) keys.collect { |key| content_tag(:div, flash[key], :class => "flash #{key}") if flash[key] }.join end [/code] Then, in my master layout, for the main section, I have: [code] <div id="main"> <div id="main_padding"> <%= flash_div :warning, :notice, :error %> <%= yield %> </div> </div> [/code] Then I style it using: [code] #flashdiv { float:left; margin-left:20px; margin-top:10px; } .flash{ padding:10px; margin-bottom: 1em; } .warning{ background:#f3b9ba; border: 1px solid #d8aeaf; } .notice{ background-color:#c8f4ba; border: 1px solid #b0d6a3; } .notice strong{ background-color:#bee4b2; padding: 2px; } .error{ background:#ff0000; color: #fff; } [/code] This works very well... it gives me a nice, style flash that is color- coded for the type (warning, error, notice). Also, it fades away and the DOM element is actually removed. Enjoy! -Danimal On Apr 15, 7:56 am, "Brian Hogan" <bpho...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Just curious how others render flash[:notice] and others in their views... > Most Rails devs I see do something like this (overly simplified example) > > (application.html.erb) > > ... > > <% if flash[:notice].blaink? %> > <div id="notice"> > <%= flash[:notice] %> > </div> > <% end %> > > <div id="main"> > <%=yield %> > </div> > > .... > > Of course, this puts the flash above the main page content (your views.) > I''ve noticed a few times that the notifications aren''t noticeable, no matter > how much you style them. So, my question is, what do others do? Place the > flash output in every view rather than in the layouts? Do you use > JavaScript to move the div to a new location in the DOM? > > Thanks for your input! It should be neat to see different solutions.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I just style a #notice div with CSS, and then in my application layout file, right above yield, I have: <%= "<div id=''notice''>#{flash[:notice]}</div>" if flash[:notice] %> And then to make it fade out after 5 seconds: <% if flash[:notice] %> <script type="text/javascript"> new Effect.Fade(''notice'', { delay: 5 }); </script> <% end %> On Apr 15, 7:56 am, "Brian Hogan" <bpho...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Just curious how others render flash[:notice] and others in their views... > Most Rails devs I see do something like this (overly simplified example) > > (application.html.erb) > > ... > > <% if flash[:notice].blaink? %> > <div id="notice"> > <%= flash[:notice] %> > </div> > <% end %> > > <div id="main"> > <%=yield %> > </div> > > .... > > Of course, this puts the flash above the main page content (your views.) > I''ve noticed a few times that the notifications aren''t noticeable, no matter > how much you style them. So, my question is, what do others do? Place the > flash output in every view rather than in the layouts? Do you use > JavaScript to move the div to a new location in the DOM? > > Thanks for your input! It should be neat to see different solutions.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
fredistic
2008-Apr-15 22:40 UTC
Re: How do you display your Flash messages in your layouts?
The styling works but the fading doesn''t. I like the solution by AtsoK, but I haven''t tried it yet. I did [body onload=.. to make the error pulsate, and it seems not to be a problem when the id isn''t found (when there is no error in flash). The visual_effect call just generates javascript as a string. It would need [script] tag to execute. Or an onsomething="code" thing. And what element has the ''flashdiv'' id ? And don''t we need a ''render :update'' or something similar to call an rjs or an action for this happen? In any case, I''m not sure I want my messages to fade away, people will turn their heads and come back and it''s gone... Still, it''s not bad looking. Did it fade for you? What browser were you using? F --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bryan Ray
2008-Apr-15 23:07 UTC
Re: How do you display your Flash messages in your layouts?
The fading would be implemented by a javascript method... There is a post on this at: http://blog.andreasaderhold.com/2006/07/rails-notifications On Tue, Apr 15, 2008 at 5:40 PM, fredistic <fredistic-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > The styling works but the fading doesn''t. I like the solution by > AtsoK, but I haven''t tried it yet. I did [body onload=.. to make > the error pulsate, and it seems not to be a problem when the id isn''t > found (when there is no error in flash). > > The visual_effect call just generates javascript as a string. It would > need [script] tag to execute. Or an onsomething="code" thing. > > And what element has the ''flashdiv'' id ? > > And don''t we need a ''render :update'' or something similar to call an > rjs or an action for this happen? > > In any case, I''m not sure I want my messages to fade away, people will > turn their heads and come back and it''s gone... > > Still, it''s not bad looking. > > Did it fade for you? What browser were you using? > > F > > > >-- Bryan Ray http://www.bryanray.net "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
My solution is to use a div across the bottom of the screen, built into the layout. The div is attached to the bottom of the window by using fixed. As others have done, i use styling to set the color of the div to different colors for different messages. The nice thing about this approach is that it if you need to be able to get to fields underneath, you can arrange to leave some blank at the bottom of the main screen so that it can be scrolled up, putting any covered fields above the div. Also, to be able to see anything below the div, I use a hover transparent style. Also, the div can expand upwards so that multiple messages can be displayed. If the div is in the way, I have made it clickable with a remote call to the main page which simply replaces the div content with an empty string. I populate the contents of the div with a partial called all_messages. At the moment, this partial gets its content from a helper called all_messages. This helper combines flash and error messages. Instead of using the standard error_messages_for helper. What I do is set a variable @errors_for in the view, which the helper then uses to set the content for the partial that creates the div at the bottom of the screen. It sounds a bit complex, but it works like a dream. All I ever have to remember to do is set the @errors_for with the models that I want errors for, just the same as the error_messages_for helper. Finally, I can also populate it from an ajax call by including a page.replace_html ''prompt'', :partial=>''layouts/all_messages'' which will also ensure any flash or error messages are displayed from an ajax call. I think it can be improved by use of content for, but havn''t got round to thinking it through quite yet. May be of some help. Tonypm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Tonypm, I''m trying to accomplish something similar with my application right now, but I seem to be missing some vital step to bridge the final gap between "including a page.replace_html ''prompt'', :partial=>''layouts/ all_messages'' " and the rest of it. Do you have a global way of rendering the partial or do you include code in all your controller actions to make that happen? On Apr 17, 2:33 pm, tonypm <tonypmar...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> My solution is to use a div across the bottom of the screen, built > into the layout. > > The div is attached to the bottom of the window by using fixed. > > As others have done, i use styling to set the color of the div to > different colors for different messages. > > The nice thing about this approach is that it if you need to be able > to get to fields underneath, you can arrange to leave some blank at > the bottom of the main screen so that it can be scrolled up, putting > any covered fields above the div. > > Also, to be able to see anything below the div, I use a hover > transparent style. > > Also, the div can expand upwards so that multiple messages can be > displayed. If the div is in the way, I have made it clickable with a > remote call to the main page which simply replaces the div content > with an empty string. > > I populate the contents of the div with a partial called > all_messages. At the moment, this partial gets its content from a > helper called all_messages. This helper combinesflashand error > messages. Instead of using the standard error_messages_for helper. > What I do is set a variable @errors_for in the view, which the helper > then uses to set the content for the partial that creates the div at > the bottom of the screen. > > It sounds a bit complex, but it works like a dream. All I ever have > to remember to do is set the @errors_for with the models that I want > errors for, just the same as the error_messages_for helper. > > Finally, I can also populate it from anajaxcall by including a > page.replace_html ''prompt'', :partial=>''layouts/all_messages'' > which will also ensure anyflashor error messages are displayed from > anajaxcall. > > I think it can be improved by use of content for, but havn''t got round > to thinking it through quite yet. > > May be of some help. > Tonypm--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
tmo26 I was thinking about that point just the other day. At the moment, I have to explicitly put that replace_html/partial line in all my actions where I may be needing a flash or error message. It would be nice if that got included automatically, but I havnt given it any real thought. I guess it would be a matter of introducing something into the render method, but that could be messy. I''ll give it a bit more thought in the near future and if I do come up with anything, I''ll let you know - or if anyone else has any ideas they would be welcome. Thanks Tonypm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''ve used something similar to AtsoK: <%= content_tag(:div, flash[:notice], :class => ''notice'') if flash[:notice] %> On Apr 15, 6:40 pm, fredistic <fredis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The styling works but the fading doesn''t. I like the solution by > AtsoK, but I haven''t tried it yet. I did [body onload=.. to make > the error pulsate, and it seems not to be a problem when the id isn''t > found (when there is no error in flash). > > The visual_effect call just generates javascript as a string. It would > need [script] tag to execute. Or an onsomething="code" thing. > > And what element has the ''flashdiv'' id ? > > And don''t we need a ''render :update'' or something similar to call an > rjs or an action for this happen? > > In any case, I''m not sure I want my messages to fade away, people will > turn their heads and come back and it''s gone... > > Still, it''s not bad looking. > > Did it fade for you? What browser were you using? > > F--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''ve used a solution similar to AstoK: <%= content_tag(:div, flash[:notice], :class => ''notice'') if flash[:notice] %> best. mike On Apr 15, 6:40 pm, fredistic <fredis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The styling works but the fading doesn''t. I like the solution by > AtsoK, but I haven''t tried it yet. I did [body onload=.. to make > the error pulsate, and it seems not to be a problem when the id isn''t > found (when there is no error in flash). > > The visual_effect call just generates javascript as a string. It would > need [script] tag to execute. Or an onsomething="code" thing. > > And what element has the ''flashdiv'' id ? > > And don''t we need a ''render :update'' or something similar to call an > rjs or an action for this happen? > > In any case, I''m not sure I want my messages to fade away, people will > turn their heads and come back and it''s gone... > > Still, it''s not bad looking. > > Did it fade for you? What browser were you using? > > F--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Fernando Perez
2008-Dec-01 20:28 UTC
Re: How do you display your Flash messages in your layouts?
AtsoK wrote:> I just style a #notice div with CSS, and then in my application layout > file, right above yield, I have: > > <%= "<div id=''notice''>#{flash[:notice]}</div>" if flash[:notice] %> > > And then to make it fade out after 5 seconds: > > <% if flash[:notice] %> > <script type="text/javascript"> > new Effect.Fade(''notice'', { delay: 5 }); > </script> > <% end %>Really cool trick. It''s exactly what I was looking for. Do you have any idea how to combine visual_effects? The doc for scriptaculous is broken at github, it misses the demo page. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---