# Form questions

**URL:** <https://www.ruby-forum.com/t/form-questions/74274>\
**Category:** Rails\
**Created:** [February 27, 2006, 5:54pm UTC](https://www.ruby-forum.com/t/form-questions/74274 "2006-02-27T17:54:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vapidbabble](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/fbc32d/32.png) [@vapidbabble](https://www.ruby-forum.com/u/vapidbabble)\
**Post date:** [February 27, 2006, 5:54pm UTC](https://www.ruby-forum.com/t/form-questions/74274/1 "2006-02-27T17:54:44Z")

</div>

I have a very simple form that looks allows an input for an error code  
and then give the show page from the scaffolding if the error code is  
in the database and a notification on the list page, again from the  
scaffolding if not.

Here’s the form:  
find.rhtml

# Find error
\<%= start\_form\_tag :action =\> 'search'%\>

Code  
\<%= text\_field 'message', 'code' %\>

 \<%= submit\_tag 'Search' %\> \<%= end\_form\_tag %\>

\<%= link\_to ‘Back’, :action =\> ‘list’ %\>

Here’s the method, search in the controller

def search  
code=params[:message][“code”]  
@message = Message.find\_by\_code(code)  
if @message.nil?  
#render :action =\> ‘find’  
flash[:notice] = “Code #{code} not found!\n Please choose a  
code from this list”  
flash[:error] = ‘Boom’  
redirect\_to :action =\> ‘list’  
else  
redirect\_to :action =\> ‘show’, :id =\> @message  
end  
end

It works except for the fact that flash[:error] does not display and  
in fact if I try :error for the first flash, it will not display.

Aside from this problem is their a better way to do this. I have the  
agile book and googled quite a bit to finally find how to pass  
non-database elements from a form to the controller, but I’ve lost the  
link. I’m new to web apps so I don’t know what the accepted practice  
is for something like this so any helpful advise or criticism is  
appreciated.

## – -john

The deep fascination of myths is that they speak directly to deeper  
levels of our nature and to the subconscious, and give the profound  
assurance that we are each, in essence, deathless and immortal sparks  
of Divinity on the long evolutionary journey into higher consciousness.

- Sir George Trevelyn

---

<div class="post-metadata">

**Author:** ![vapidbabble](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/fbc32d/32.png) [@vapidbabble](https://www.ruby-forum.com/u/vapidbabble)\
**Post date:** [March 2, 2006, 10:07am UTC](https://www.ruby-forum.com/t/form-questions/74274/2 "2006-03-02T10:07:25Z")

</div>

Hi, Vapid,

did you change anything on the scaffolded layout. In your view/layouts  
folder is there a scaffold layout for the controller? And in this  
layout: Is  
there display code for the flash notice?

Regards  
Jan P.

---

<div class="post-metadata">

**Author:** ![vapidbabble](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/fbc32d/32.png) [@vapidbabble](https://www.ruby-forum.com/u/vapidbabble)\
**Post date:** [March 14, 2006, 3:47am UTC](https://www.ruby-forum.com/t/form-questions/74274/3 "2006-03-14T03:47:58Z")

</div>

Doesn’t look like you’re doing anything with flash[:error] in your view.  
The  
flash[:notice] shows up because the basic layout generated by scaffold  
puts

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

in there… Try putting that with :error instead… bet yah it’ll work.

b

PS: I actually saved the model object in the flash on error, cuz that  
has all the errors  
in it. Then I can use error\_messages\_for in the view.

---

<div class="post-metadata">

**Author:** ![vapidbabble](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/fbc32d/32.png) [@vapidbabble](https://www.ruby-forum.com/u/vapidbabble)\
**Post date:** [March 14, 2006, 12:12am UTC](https://www.ruby-forum.com/t/form-questions/74274/4 "2006-03-14T00:12:54Z")

</div>

I did everything in the generated controller, so I didn’t change the  
layout. I’m not sure about your last question? I just call flash.  
With :notice it works, with :error it does not. I’ll double check my  
Agile book but from what you are saying I didn’t supply the needed  
display code for error.

On 3/2/06, Jan P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 2/27/06, Vapid Babble [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> Code  
> @message = Message.find\_by\_code(code)
> 
> –  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

## – -john
