Displaying flash message in portion of page that is otherwise not updated

I'm looking to display my flash messages in a portion of the page that is otherwise not always in a partial that gets updated.

In other words, I may submit a form that updates a partial via ajax. But I want to display the flash message in a portion of the page that is outside of that partial.

I could have some javascript in every single necessary js.erb file to update the flash partial, but that seems crazy. Is there a more simple way of going about this?

I don't have to necessarily use flash messages either if something custom would work better.

Thanks!

Answers


You can do it the low-tech way by using a :remote call on your form that, when executed, will inject some HTML back into your page from a partial of your choosing.

It's pretty easy to do in a .rjs view:

page['flash'].html(render(:partial => 'flash'))

You can also do it in a .js.erb view using jQuery:

$('#flash').html("<%= escape_javascript(render(:partial => 'flash')) %>");

I tend to think the .js.erb method is a lot more ugly, but we all have our preferences.


Need Your Help

DateTime.ToLocalTime() stopped working on XP in August 2013

vb.net datetime dst windows-update

We have a VB.NET application installed on a customer's PC running XP, on which it appears that DateTime.ToLocalTime() has stopped working.

Error on didselect tableview on SWRevealViewController

ios uitableview ios9 swrevealviewcontroller

when i worked with slide out menu using SWRevealViewController class ,it works correctly in iphone simulator.But when i tried to run in the iphone 5 device for testing,while selecting the menu but...