# Flash\[:error\] -- nothing happens

**URL:** <https://www.ruby-forum.com/t/flash-error-nothing-happens/130052>\
**Category:** Rails\
**Created:** [February 25, 2008, 12:10am UTC](https://www.ruby-forum.com/t/flash-error-nothing-happens/130052 "2008-02-25T00:10:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a3d4f5/32.png) [@anti](https://www.ruby-forum.com/u/anti)\
**Post date:** [February 25, 2008, 12:10am UTC](https://www.ruby-forum.com/t/flash-error-nothing-happens/130052/1 "2008-02-25T00:10:47Z")

</div>

in the case of invalid login, the method bellow does nothing at  
flash[:error], just goes directly to =\>welcome page.  
is something missing something?

def process\_login  
if user = User.authenticate(params[:user])  
session[:id] = user.id  
redirect\_to session[:return\_to] || ‘/’  
else  
flash[:error] = “Invalid login.”  
puts ‘error’  
redirect\_to :controller =\> ‘main’, :action =\>  
‘welcome’, :username =\> params[:user][:username]  
end  
end

in \*.erb code is as follows

\<% if flash[:message] %\>

\<%= flash[:message] %\>
  
\<% end %\>

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

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

---

<div class="post-metadata">

**Author:** ![anti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a3d4f5/32.png) [@anti](https://www.ruby-forum.com/u/anti)\
**Post date:** [February 25, 2008, 8:52am UTC](https://www.ruby-forum.com/t/flash-error-nothing-happens/130052/2 "2008-02-25T08:52:35Z")

</div>

anti wrote:

> > in \*.erb code is as follows

Is it really in all of your .erb files? In a layout file?

If I understand correctly, you’re expecting it to show the error on the  
welcome page, yes? If so, is the flash stuff in the Welcome.html.erb  
file, or the layout it uses?

jp

---

<div class="post-metadata">

**Author:** ![anti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a3d4f5/32.png) [@anti](https://www.ruby-forum.com/u/anti)\
**Post date:** [February 25, 2008, 9:42am UTC](https://www.ruby-forum.com/t/flash-error-nothing-happens/130052/3 "2008-02-25T09:42:18Z")

</div>

anti wrote:

> in the case of invalid login, the method bellow does nothing at  
> flash[:error], just goes directly to =\>welcome page.  
> is something missing something?

How is the “welcome” action in your “main” controller defined? What  
entries are there in your log file during invalid login processing (at  
least processing, parameter and rendering lies)?

---

<div class="post-metadata">

**Author:** ![anti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a3d4f5/32.png) [@anti](https://www.ruby-forum.com/u/anti)\
**Post date:** [February 25, 2008, 9:52am UTC](https://www.ruby-forum.com/t/flash-error-nothing-happens/130052/4 "2008-02-25T09:52:19Z")

</div>

anti wrote:

> in the case of invalid login, the method bellow does nothing at  
> flash[:error], just goes directly to =\>welcome page.  
> is something missing something?
> 
> def process\_login  
> if user = User.authenticate(params[:user])  
> session[:id] = user.id  
> redirect\_to session[:return\_to] || ‘/’  
> else  
> flash[:error] = “Invalid login.”  
> puts ‘error’  
> redirect\_to :controller =\> ‘main’, :action =\>  
> ‘welcome’, :username =\> params[:user][:username]  
> end  
> end
> 
> in \*.erb code is as follows
> 
> \<% if flash[:message] %\>
> 
> \<%= flash[:message] %\>
>   
> \<% end %\>
> 
> \<% if flash[:error] %\>
> 
> \<%= flash[:error] %\>
>   
> \<% end %\>

hi anti…

the prob here is u have to specify even the id of the div  
it should be probably like this  
try once

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

---

<div class="post-metadata">

**Author:** ![anti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a3d4f5/32.png) [@anti](https://www.ruby-forum.com/u/anti)\
**Post date:** [February 25, 2008, 2:04pm UTC](https://www.ruby-forum.com/t/flash-error-nothing-happens/130052/5 "2008-02-25T14:04:42Z")

</div>

this is it.

> If I understand correctly, you’re expecting it to show theerroron the  
> welcome page, yes? If so, is theflashstuff in the Welcome.html.erb  
> file, or the layout it uses?

theflashstuff has to be on the destination page, welcome.html.erb in  
this case.

theflashstuff goes on the same page when the action is to itself.
