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
Michael Gorsuch wrote:> 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?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.
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 On 11/19/05, Simon Santoro <Simon.Santoro-Syd3ARw+vPY@public.gmane.org> wrote:> Michael Gorsuch wrote: > > 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? > > 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. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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
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? On 11/22/05, Kamil Kukura <kamil.kukura-iKbljaP1DMalVyrhU4qvOw@public.gmane.org> wrote:> 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 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I guess that would be the lib directory On 11/22/05, Michael Gorsuch <michael.gorsuch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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? > > On 11/22/05, Kamil Kukura <kamil.kukura-iKbljaP1DMalVyrhU4qvOw@public.gmane.org> wrote: > > 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 > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
That would go in the models directory. It''s very handy to use non-persisted model objects like this. -Tom On 11/22/05, Michael Gorsuch <michael.gorsuch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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? > > On 11/22/05, Kamil Kukura <kamil.kukura-iKbljaP1DMalVyrhU4qvOw@public.gmane.org> wrote: > > 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 >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails