Forum: Ruby on Rails "Persisting" Forms

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2c80e1b0837eec76d38d4f7fa1c15e87?d=identicon&s=25 michael.gorsuch (Guest)
on 2005-11-19 04:53
(Received via mailing list)
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
B6e90ad1e69d563f1f13cccffe137262?d=identicon&s=25 Simon.Santoro (Guest)
on 2005-11-19 15:18
(Received via mailing list)
Michael Gorsuch 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.
2c80e1b0837eec76d38d4f7fa1c15e87?d=identicon&s=25 michael.gorsuch (Guest)
on 2005-11-19 15:39
(Received via mailing list)
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
2a73a242ac582b27e841b4bce6ba1373?d=identicon&s=25 kamil.kukura (Guest)
on 2005-11-22 09:27
(Received via mailing list)
Michael Gorsuch 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
2c80e1b0837eec76d38d4f7fa1c15e87?d=identicon&s=25 michael.gorsuch (Guest)
on 2005-11-22 12:56
(Received via mailing list)
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?
531eb73f8fbf05a197721d02b4e6aadb?d=identicon&s=25 bogdan.ionescu (Guest)
on 2005-11-22 14:05
(Received via mailing list)
I guess that would be the lib directory
6b655cbfb773c06803214fdf03fa8d1c?d=identicon&s=25 tomwilcoxen (Guest)
on 2005-11-22 16:01
(Received via mailing list)
That would go in the models directory. It's very handy to use
non-persisted
model objects like this.

-Tom
This topic is locked and can not be replied to.