I figured out how to get it done. My situation was a bit different than the norm but the following works:
in my rjs:
page.replace_html("headstart" , :partial => "headstart" , :object => @teamnames) if @flashsetting == false page.replace_html("teamheaders" , :partial => "teamheaders" , :object => @teamnames) page.replace_html("team0" , :partial => "team0" , :object => @teamnames) page.replace_html("boxscore" , :partial => "boxscore" , :object => @teamnames) page.replace_html :notice, "" flash.discard
in my controller:
def validate_team_select(teamone,teamtwo) if teamone == teamtwo && teamone != "" flash[:notice] = 'You cannot compare a team to itself!' virtual_redirect elsif teamone == "" || teamtwo == "" flash[:notice] = 'You must select two unique teams!' virtual_redirect else virtual_response(teamone, teamtwo) end end
def virtual_redirect respond_to do |format| format.html { redirect_to virtual_matchups_path } format.js { render :update do |page| page.replace_html :notice, flash[:notice] end } end end
Then I placed a notice div inside the actual view and not in the layout, nesting a partial to the notice alert with css coloring..
This works well in that it performs all my ajax requests through a standard process but if it reaches a validation error, it goes to the virtual_redirect which displays the correct messages without altering the view on the page.
When it does validate correctly, the message is cleared and flash notices are discarded on subsequent page redirects.