Forum: Ruby on Rails Best place to set the flash[:notice] ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
zorn (Guest)
on 2009-01-24 14:27
(Received via mailing list)
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
http://clickablebliss.com/
This topic is locked and can not be replied to.