sachin238-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-03 14:05 UTC
how to fill select box with the names of the states corresponding to the country name selected in different select box
hi all , can any body guide me, i have to fill the dropdown box with the name of the states of the country at run time which is dependent on the name of the country you selected. is their any helper exists for this. thanks sachin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe
2007-Dec-03 14:42 UTC
Re: how to fill select box with the names of the states corresponding to the country name selected in different select box
Hi Sachin, Something like this: in your controller @states = State.find_by_country(params[:country]) then in your view <%= form.collection_select :state_id, @states, :id, :state %> This example is based on form_for, so if you are using form_tag, you''ll need the additional parameter at the beginning <%= collection_select :person, :state_id, @states, :id, :state %> Something like that anyway. Peace, Phillip On Dec 3, 2007, at 8:05 AM, sachin238-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > hi all , > > can any body guide me, i have to fill the dropdown box with the name > of the states of the country at run time which is dependent on the > name of the country you selected. > > is their any helper exists for this. > > thanks > sachin > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe
2007-Dec-03 16:24 UTC
Fwd: [Rails] how to fill select box with the names of the states corresponding to the country name selected in different select box
Oy. I just realized that I didn''t read the message closely enough. I see now that you are needing to do one of two things: 1) post the form when the country is selected, use the code I mentioned earlier (or something similiar) and render the form again, or 2) use AJAX to query the database and repopulate the state select when the country changes. I, personally, would go with #2. There is the argument that your app should degrade gracefully if the user doesn''t have JavaScript enabled, but I ignore that since my whole app depends on JavaScript and I doubt that very many people actually have it disabled these days. But that''s an architectural decision that I''ve made. Not everyone would be comfortable with it. I can provide an example of #2 if you like. Sorry for the seeming incompetence on my part. I''ll try to read more closely in the future. Peace, Phillip Begin forwarded message:> From: Phillip Koebbe <phillipkoebbe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > Date: December 3, 2007 8:42:28 AM CST > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: Re: [Rails] how to fill select box with the names of the > states corresponding to the country name selected in different > select box > > Hi Sachin, > > Something like this: > > in your controller > > @states = State.find_by_country(params[:country]) > > then in your view > > <%= form.collection_select :state_id, @states, :id, :state %> > > This example is based on form_for, so if you are using form_tag, > you''ll need the additional parameter at the beginning > > <%= collection_select :person, :state_id, @states, :id, :state %> > > Something like that anyway. > > Peace, > Phillip > > On Dec 3, 2007, at 8:05 AM, sachin238-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > >> >> hi all , >> >> can any body guide me, i have to fill the dropdown box with the name >> of the states of the country at run time which is dependent on the >> name of the country you selected. >> >> is their any helper exists for this. >> >> thanks >> sachin >> >> >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sachin238-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-05 06:40 UTC
Re: Fwd: [Rails] how to fill select box with the names of the states corresponding to the country name selected in different select box
please forward me the example if it is possible for you thanks On Dec 3, 9:24 pm, Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Oy. I just realized that I didn''t read the message closely enough. > I see now that you are needing to do one of two things: > > 1) post the form when the country is selected, use the code I > mentioned earlier (or something similiar) and render the form again, or > 2) use AJAX to query the database and repopulate the state select > when the country changes. > > I, personally, would go with #2. There is the argument that your app > should degrade gracefully if the user doesn''t have JavaScript > enabled, but I ignore that since my whole app depends on JavaScript > and I doubt that very many people actually have it disabled these > days. But that''s an architectural decision that I''ve made. Not > everyone would be comfortable with it. > > I can provide an example of #2 if you like. > > Sorry for the seeming incompetence on my part. I''ll try to read more > closely in the future. > > Peace, > Phillip > > Begin forwarded message: > > > From: Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > Date: December 3, 2007 8:42:28 AM CST > > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > Subject: Re: [Rails] how to fill select box with the names of the > > states corresponding to the country name selected in different > > select box > > > Hi Sachin, > > > Something like this: > > > in your controller > > > @states = State.find_by_country(params[:country]) > > > then in your view > > > <%= form.collection_select :state_id, @states, :id, :state %> > > > This example is based on form_for, so if you are using form_tag, > > you''ll need the additional parameter at the beginning > > > <%= collection_select :person, :state_id, @states, :id, :state %> > > > Something like that anyway. > > > Peace, > > Phillip > > > On Dec 3, 2007, at 8:05 AM, sachin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > >> hi all , > > >> can any body guide me, i have to fill the dropdown box with the name > >> of the states of the country at run time which is dependent on the > >> name of the country you selected. > > >> is their any helper exists for this. > > >> thanks > >> sachin--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sachin238-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-05 06:48 UTC
Re: Fwd: [Rails] how to fill select box with the names of the states corresponding to the country name selected in different select box
one more thing in your code what i realize is that i must have state table in my database, which contains the name of the states for the respective country or it is rails helper kind of thing please confirm thanks On Dec 5, 11:40 am, "sachin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <sachin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> please forward me the example if it is possible for you thanks > > On Dec 3, 9:24 pm, Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Oy. I just realized that I didn''t read the message closely enough. > > I see now that you are needing to do one of two things: > > > 1) post the form when the country is selected, use the code I > > mentioned earlier (or something similiar) and render the form again, or > > 2) use AJAX to query the database and repopulate the state select > > when the country changes. > > > I, personally, would go with #2. There is the argument that your app > > should degrade gracefully if the user doesn''t have JavaScript > > enabled, but I ignore that since my whole app depends on JavaScript > > and I doubt that very many people actually have it disabled these > > days. But that''s an architectural decision that I''ve made. Not > > everyone would be comfortable with it. > > > I can provide an example of #2 if you like. > > > Sorry for the seeming incompetence on my part. I''ll try to read more > > closely in the future. > > > Peace, > > Phillip > > > Begin forwarded message: > > > > From: Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > Date: December 3, 2007 8:42:28 AM CST > > > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > > Subject: Re: [Rails] how to fill select box with the names of the > > > states corresponding to the country name selected in different > > > select box > > > > Hi Sachin, > > > > Something like this: > > > > in your controller > > > > @states = State.find_by_country(params[:country]) > > > > then in your view > > > > <%= form.collection_select :state_id, @states, :id, :state %> > > > > This example is based on form_for, so if you are using form_tag, > > > you''ll need the additional parameter at the beginning > > > > <%= collection_select :person, :state_id, @states, :id, :state %> > > > > Something like that anyway. > > > > Peace, > > > Phillip > > > > On Dec 3, 2007, at 8:05 AM, sachin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > > >> hi all , > > > >> can any body guide me, i have to fill the dropdown box with the name > > >> of the states of the country at run time which is dependent on the > > >> name of the country you selected. > > > >> is their any helper exists for this. > > > >> thanks > > >> sachin--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ayyanar Aswathaman
2007-Dec-05 06:57 UTC
Re: Fwd: [Rails] how to fill select box with the names of the states corresponding to the country n
sachin238-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> one more thing in your code what i realize is that i must have state > table in my database, which contains the name of the states for the > respective country or it is rails helper kind of thing > > please confirm > > thanksProbably, you can use observe_field to post the ajax request when country is getting changed -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ayyanar Aswathaman
2007-Dec-05 09:54 UTC
Re: Fwd: [Rails] how to fill select box with the names of the states corresponding to the country n
Use render :inline to populate the values for the state dropdown. Summarize: 1) Post the AJAX request to the controller by using Observe_field 2) Populate the state dropdown values using render :inline. You can write the logic in the controller action where you posted the AJAX requset. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---