# "Persisting" Forms

**URL:** <https://www.ruby-forum.com/t/persisting-forms/48343>\
**Category:** Rails\
**Created:** [November 19, 2005, 4:53am UTC](https://www.ruby-forum.com/t/persisting-forms/48343 "2005-11-19T04:53:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.gorsuch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@michael.gorsuch](https://www.ruby-forum.com/u/michael.gorsuch)\
**Post date:** [November 19, 2005, 4:53am UTC](https://www.ruby-forum.com/t/persisting-forms/48343/1 "2005-11-19T04:53:52Z")

</div>

I am building a search form for my application that is not directly  
tied to a model.

I would like to search results page to display the original search  
form with the inputted values along with the results.

I have everything in order, but when the form is posted, the form on  
the results page is set back to the defaults. I have figured out how  
to get my text\_field\_tag to keep the appropriate value, but is there  
an easy way to do this with selection lists (using select\_tag) to do  
this as well?

Thank you for your assistance,

Michael

---

<div class="post-metadata">

**Author:** ![michael.gorsuch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@michael.gorsuch](https://www.ruby-forum.com/u/michael.gorsuch)\
**Post date:** [November 19, 2005, 3:18pm UTC](https://www.ruby-forum.com/t/persisting-forms/48343/2 "2005-11-19T15:18:46Z")

</div>

Michael G. wrote:

> this as well?  
> If your form is tied to a model object (that means you use \<%= select  
> ‘object’, ‘method’ %\> helpers) you can just pass the filled @object  
> variable back to your view, and it will display the filled in values.

---

<div class="post-metadata">

**Author:** ![michael.gorsuch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@michael.gorsuch](https://www.ruby-forum.com/u/michael.gorsuch)\
**Post date:** [November 19, 2005, 3:39pm UTC](https://www.ruby-forum.com/t/persisting-forms/48343/3 "2005-11-19T15:39:56Z")

</div>

My form actually wasn’t tied to a model. I ended up overcoming the  
issue by using the select\_tag and building the options via code.

No big deal, really. Just needed to be in the right state of mind.

Thanks,

Michael

---

<div class="post-metadata">

**Author:** ![michael.gorsuch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@michael.gorsuch](https://www.ruby-forum.com/u/michael.gorsuch)\
**Post date:** [November 22, 2005, 9:27am UTC](https://www.ruby-forum.com/t/persisting-forms/48343/4 "2005-11-22T09:27:04Z")

</div>

Michael G. wrote:

> My form actually wasn’t tied to a model. I ended up overcoming the  
> issue by using the select\_tag and building the options via code.
> 
> No big deal, really. Just needed to be in the right state of mind.

Hmm, I use my own objects like:

class FormValues  
attr\_accessor :field1, :field2

```
 def initialize(p = {})
     field1 = p[:field1] || 'default value'
     field2 = p[:field2] || 'default value'
     # ...
 end

```

end

@form = FormValues.new # to load it with default values  
@form = FormValues.new(params[:form]) # to load it with posted values

–  
Kamil

---

<div class="post-metadata">

**Author:** ![michael.gorsuch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@michael.gorsuch](https://www.ruby-forum.com/u/michael.gorsuch)\
**Post date:** [November 22, 2005, 12:56pm UTC](https://www.ruby-forum.com/t/persisting-forms/48343/5 "2005-11-22T12:56:34Z")

</div>

Now that makes a lot of sense. LOTS more than my method.

In Rails, where do you define your extra classes? Do I create an .rb  
file in my models directory, or is this a helper?

---

<div class="post-metadata">

**Author:** ![michael.gorsuch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@michael.gorsuch](https://www.ruby-forum.com/u/michael.gorsuch)\
**Post date:** [November 22, 2005, 4:01pm UTC](https://www.ruby-forum.com/t/persisting-forms/48343/6 "2005-11-22T16:01:49Z")

</div>

That would go in the models directory. It’s very handy to use  
non-persisted  
model objects like this.

-Tom

---

<div class="post-metadata">

**Author:** ![michael.gorsuch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f1d935/32.png) [@michael.gorsuch](https://www.ruby-forum.com/u/michael.gorsuch)\
**Post date:** [November 22, 2005, 2:05pm UTC](https://www.ruby-forum.com/t/persisting-forms/48343/7 "2005-11-22T14:05:04Z")

</div>

I guess that would be the lib directory
