I''ve got a select tag that has all 50 states as options, and I already have the HTML that has all the states. Still, I''d like to be able to use the Rails helper to output the select tag, primarily for the error handling. Is there any way I can do like a start_select_tag, have all the HTML options, and then end_select_tag? I don''t really see a need to create an array of options that gets passed in. Thanks, Pat
Well, at that point, I wouldn''t bother. The rails tags really only help you out when dealing with the database objects. Don''t fear the html! The error handling happens on the model Say you''ve got a field in your DB called "state" and your model is "address" Well, just do this for your select tag <select name="address[state]"> <option selected="selected"></option> .... <option value="VA">Virginia</option> </state> The only thing you don''t get by doing this is that your current state value won''t get re-selected for you when you throw an error. Your validation will still work though. As for reselecting the value, I''m not sure how to handle that part in this situation. I''ve come across this before and I''ve just done it manually. I''d love to hear suggestions from others on how to handle this. On 9/22/05, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''ve got a select tag that has all 50 states as options, and I already > have the HTML that has all the states. Still, I''d like to be able to > use the Rails helper to output the select tag, primarily for the error > handling. Is there any way I can do like a start_select_tag, have all > the HTML options, and then end_select_tag? I don''t really see a need > to create an array of options that gets passed in. > > Thanks, > Pat > _______________________________________________ > 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
What I mean by error handling is displaying the error messages if that particular field fails validation. Rails will automatically wrap it in a div, right? I''d like that, autofill, etc. I''m using Rails so I can have some of these goodies cheap, why not with a select tag as well? Pat On 9/22/05, Brian Hogan <bphogan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Well, at that point, I wouldn''t bother. The rails tags really only help you > out when dealing with the database objects. > > Don''t fear the html! The error handling happens on the model > > Say you''ve got a field in your DB called "state" and your model is > "address" > > Well, just do this for your select tag > > <select name="address[state]"> > <option selected="selected"></option> > .... > <option value="VA">Virginia</option> > </state> > > > The only thing you don''t get by doing this is that your current state value > won''t get re-selected for you when you throw an error. Your validation will > still work though. > As for reselecting the value, I''m not sure how to handle that part in this > situation. I''ve come across this before and I''ve just done it manually. I''d > love to hear suggestions from others on how to handle this. > > > > > On 9/22/05, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''ve got a select tag that has all 50 states as options, and I already > > have the HTML that has all the states. Still, I''d like to be able to > > use the Rails helper to output the select tag, primarily for the error > > handling. Is there any way I can do like a start_select_tag, have all > > the HTML options, and then end_select_tag? I don''t really see a need > > to create an array of options that gets passed in. > > > > Thanks, > > Pat > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >
Maybe what you want is something like collection_select? http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html #M000324 -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Pat Maddox Sent: Thursday, September 22, 2005 10:15 AM To: Brian Hogan; rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] Specify select options in HTML? What I mean by error handling is displaying the error messages if that particular field fails validation. Rails will automatically wrap it in a div, right? I''d like that, autofill, etc. I''m using Rails so I can have some of these goodies cheap, why not with a select tag as well? Pat On 9/22/05, Brian Hogan <bphogan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Well, at that point, I wouldn''t bother. The rails tags really only helpyou> out when dealing with the database objects. > > Don''t fear the html! The error handling happens on the model > > Say you''ve got a field in your DB called "state" and your model is > "address" > > Well, just do this for your select tag > > <select name="address[state]"> > <option selected="selected"></option> > .... > <option value="VA">Virginia</option> > </state> > > > The only thing you don''t get by doing this is that your current statevalue> won''t get re-selected for you when you throw an error. Your validationwill> still work though. > As for reselecting the value, I''m not sure how to handle that part inthis> situation. I''ve come across this before and I''ve just done it manually.I''d> love to hear suggestions from others on how to handle this. > > > > > On 9/22/05, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''ve got a select tag that has all 50 states as options, and I already > > have the HTML that has all the states. Still, I''d like to be able to > > use the Rails helper to output the select tag, primarily for the error > > handling. Is there any way I can do like a start_select_tag, have all > > the HTML options, and then end_select_tag? I don''t really see a need > > to create an array of options that gets passed in. > > > > Thanks, > > Pat > > _______________________________________________ > > 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