# Redirect does not show error\_messages

**URL:** <https://www.ruby-forum.com/t/redirect-does-not-show-error-messages/150965>\
**Category:** Rails\
**Created:** [October 15, 2008, 10:27am UTC](https://www.ruby-forum.com/t/redirect-does-not-show-error-messages/150965 "2008-10-15T10:27:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [October 15, 2008, 10:27am UTC](https://www.ruby-forum.com/t/redirect-does-not-show-error-messages/150965/1 "2008-10-15T10:27:45Z")

</div>

Hi  
In the view I have  
\<%= error\_messages\_for :problem%\>  
In the model I have validations. and in controller inside transaction  
I have

@problem.save! So suppose an error happens I have redirected to the  
same view which contains error\_messages …But my problem is I dont ge  
the error messages when redirect but get it when render the same

redirect\_to :action =\> ‘create\_ui’ #This dies not give error messages  
for problem  
render :action =\> ‘create\_ui’ #This gives error messages for problem  
Why this happens ?Please help

Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [October 15, 2008, 10:34am UTC](https://www.ruby-forum.com/t/redirect-does-not-show-error-messages/150965/2 "2008-10-15T10:34:22Z")

</div>

On Oct 15, 9:27 am, Sijo Kg [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> @problem.save! So suppose an error happens I have redirected to the  
> same view which contains error\_messages …But my problem is I dont ge  
> the error messages when redirect but get it when render the same
> 
> redirect\_to :action =\> ‘create\_ui’ #This dies not give error messages

Because the state of the invalid object is lost when you do a redirect  
(which is why people typically don’t do a redirect)

Fred

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [October 15, 2008, 12:02pm UTC](https://www.ruby-forum.com/t/redirect-does-not-show-error-messages/150965/3 "2008-10-15T12:02:03Z")

</div>

Hi

Thanks for the reply.Why I used the redirect because I first used render  
But In the view I have some check boxes One of them like  
\<%= select( “problem”, “problem\_urgency\_id”,  
ProblemUrgency.find(:all).collect {|p| [p.name, p.id] },options  
={:prompt =\> “\<\< Select any \>\>”}) %\>

```
So in the above if I use render(if error happens) what happens is 

```

that  
\<\< Select any \>\> is not shown and only the values from the  
problem\_urgencies table are shown That is why I used the redirect\_to  
But it has this problem(Not problem actually)…Could you please suggest  
how I can solve this?

Thanks in advance  
Sijo
