# Flash message not being displayed

**URL:** <https://www.ruby-forum.com/t/flash-message-not-being-displayed/170783>\
**Category:** Rails\
**Created:** [June 22, 2009, 8:43pm UTC](https://www.ruby-forum.com/t/flash-message-not-being-displayed/170783 "2009-06-22T20:43:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hypnos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8797f3/32.png) [@hypnos](https://www.ruby-forum.com/u/hypnos)\
**Post date:** [June 22, 2009, 8:43pm UTC](https://www.ruby-forum.com/t/flash-message-not-being-displayed/170783/1 "2009-06-22T20:43:36Z")

</div>

I can’t seem to get a flash message to display in my app after catching  
an exception.

I have a method that loads the current user based on the current  
subdomain, the current\_subdomain\_user method throws an  
ActiveRecord::RecordNotFound if it can’t find a user for a particular  
subdomain.

I have a before\_filter that calls this method and catches any record not  
found exceptions, sets a flash message and redirects.

The problem is that the flash message isn’t being displayed, I can’t  
understand why not. Any help would be much appreciated. Below is the  
before filter

def user\_required  
begin  
current\_subdomain\_user # this method will raise an exception if  
the current subdomain user can’t be found  
rescue ActiveRecord::RecordNotFound  
flash[:error] = “Couldn’t find the user #{current\_subdomain}”  
redirect\_to root\_url(:subdomain =\> false)  
end  
end

---

<div class="post-metadata">

**Author:** ![hypnos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8797f3/32.png) [@hypnos](https://www.ruby-forum.com/u/hypnos)\
**Post date:** [June 22, 2009, 9:19pm UTC](https://www.ruby-forum.com/t/flash-message-not-being-displayed/170783/2 "2009-06-22T21:19:46Z")

</div>

Do you have something like

\<%= flash[:error] %\>

in your layout or view file?

On Jun 22, 8:43 pm, Oliver Nightingale \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![hypnos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8797f3/32.png) [@hypnos](https://www.ruby-forum.com/u/hypnos)\
**Post date:** [June 22, 2009, 9:39pm UTC](https://www.ruby-forum.com/t/flash-message-not-being-displayed/170783/3 "2009-06-22T21:39:16Z")

</div>

Yeah, I should have mentioned that sorry.

I can display flash messages, including error messages elsewhere in my  
application, I have the following code for displaying the flash messages  
in my layout.

Layout:  
\<%= flash\_messages %\>

Helper:  
def flash\_messages  
messages = []  
%w(notice warning error).each do |msg|  
messages \<\< content\_tag(:div, html\_escape(flash[msg.to\_sym]), :id  
=\> “flash-#{msg}”) unless flash[msg.to\_sym].blank?  
end  
messages  
end

---

<div class="post-metadata">

**Author:** ![hypnos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8797f3/32.png) [@hypnos](https://www.ruby-forum.com/u/hypnos)\
**Post date:** [July 14, 2009, 12:55am UTC](https://www.ruby-forum.com/t/flash-message-not-being-displayed/170783/4 "2009-07-14T00:55:36Z")

</div>

Not sure if you got this answered but a guess would be because the  
flash hash is persisted only across the same domain… your subdomain  
doesn’t see the flash message.

On Jun 22, 12:39 pm, Oliver Nightingale \<rails-mailing-l…@andreas-
