# Flash Message after each Ajax request

**URL:** <https://www.ruby-forum.com/t/flash-message-after-each-ajax-request/91275>\
**Category:** Rails\
**Created:** [April 6, 2007, 6:18am UTC](https://www.ruby-forum.com/t/flash-message-after-each-ajax-request/91275 "2007-04-06T06:18:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rails\_junkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@Rails\_junkie](https://www.ruby-forum.com/u/Rails_junkie)\
**Post date:** [April 6, 2007, 6:18am UTC](https://www.ruby-forum.com/t/flash-message-after-each-ajax-request/91275/1 "2007-04-06T06:18:21Z")

</div>

I need to enable Flash message with each request in my application.  
e.g. if i have action on addFeed, after this action is executed, I  
have a render :partial ‘showfeed’ but i also want to enable a Flash  
Message for the action ‘Feed SAved’  
I want to do this with every action in my application?  
What would be the best way to approach this?

amy thoughts?

---

<div class="post-metadata">

**Author:** ![Rails\_junkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@Rails\_junkie](https://www.ruby-forum.com/u/Rails_junkie)\
**Post date:** [April 6, 2007, 8:24pm UTC](https://www.ruby-forum.com/t/flash-message-after-each-ajax-request/91275/2 "2007-04-06T20:24:09Z")

</div>

Thanks. i will give it a shot

On Apr 6, 5:49 am, Francis S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Rails\_junkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@Rails\_junkie](https://www.ruby-forum.com/u/Rails_junkie)\
**Post date:** [April 6, 2007, 2:49pm UTC](https://www.ruby-forum.com/t/flash-message-after-each-ajax-request/91275/3 "2007-04-06T14:49:08Z")

</div>

Rails junkie wrote:

> I need to enable Flash message with each request in my application.  
> e.g. if i have action on addFeed, after this action is executed, I  
> have a render :partial ‘showfeed’ but i also want to enable a Flash  
> Message for the action ‘Feed SAved’  
> I want to do this with every action in my application?  
> What would be the best way to approach this?
> 
> amy thoughts?

In my app, what i did was extend JavaScriptGenerator:

```
            def ajax_flash_notice(message)
                id = 'notice_wrapper'
                html = render(:partial =>

```

‘global/ajax\_system\_flash’, :locals =\> {:message =\> message})  
empty\_str = “”  
#html = render(\*options\_for\_render)  
record “Element.update(#{id.inspect},  
#{html.inspect})”  
record “setTimeout(‘Element.update(#{id.inspect},  
#{empty\_str.inspect})’, 10000)”

```
            end

```

in controller action:

i set flash.now[:message] = ‘blah blah’

in .rjs

page.ajax\_flash\_notice(flash[:message])

I dunno if its the best implementation but it works for me.

---

<div class="post-metadata">

**Author:** ![Rails\_junkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@Rails\_junkie](https://www.ruby-forum.com/u/Rails_junkie)\
**Post date:** [April 6, 2007, 8:45pm UTC](https://www.ruby-forum.com/t/flash-message-after-each-ajax-request/91275/4 "2007-04-06T20:45:11Z")

</div>

Hi Francis,

call me dumb but i am still trying to understand rails architecture.  
Now my problem with that example you gave me to putting it togehter

Here is what I am thinking

def ajax\_flash\_notice will go in Application.rb

In my controller, I will simpy set Flash message

Now How does this .rjs file get called?  
this is my code

Feed.save  
Flash[type]=“Task saved”  
render : partial “showFeed”

Now how does rjs come into picture here?

I really apreciate your time.

Thanks

railsjunkie

On Apr 6, 11:23 am, “Rails junkie” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
