# Best place to set the flash\[:notice\]?

**URL:** <https://www.ruby-forum.com/t/best-place-to-set-the-flash-notice/158537>\
**Category:** Rails\
**Created:** [January 24, 2009, 1:27pm UTC](https://www.ruby-forum.com/t/best-place-to-set-the-flash-notice/158537 "2009-01-24T13:27:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zorn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/ce73a5/32.png) [@zorn](https://www.ruby-forum.com/u/zorn)\
**Post date:** [January 24, 2009, 1:27pm UTC](https://www.ruby-forum.com/t/best-place-to-set-the-flash-notice/158537/1 "2009-01-24T13:27:07Z")

</div>

I’m using some standard Rails Resource controllers and on a new  
resource creation you’ll see something like

respond\_to do |format|  
if @company.save  
flash[:notice] = ‘Company was successfully created.’  
format.html { redirect\_to(@company) }  
format.xml { render :xml =\> @company, :status  
=\> :created, :location =\> @company }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @company.errors, :status  
=\> :unprocessable\_entity }  
end  
end

Now I’m starting to add some AJAX stuff in the dashboard of the  
application and want to add a `format.js` to that list. This has me  
thinking…

Shouldn’t the flash[:notice] be inside the html block. Why is this the  
default? I’m pretty sure you don’t want to set the flash when we are  
dealing with XML requests. Similarly most xhr requests will deal with  
notification in their own way (Yellow fade effect, and so on.)

I’m just curious as to why this is the default and see how other  
people edit/use this in similar cases.

## ~ Mike

Michael Zornek  
Clickable Bliss

> **[For Hire - Mike Zornek](https://mikezornek.com/for-hire/)**
>
> Freelance software developer/consultant. Focusing on Elixir, Phoenix, teaching, and mentoring.
