In my form I have a select menu for US States. I would like to include the capitals of those states as a hidden parameter when passed to the model. Of course, the capital should match the state chosen. I know I can set a attr_accessor :state_capitals in the model, or even make a migration to update the table and add the column, but I''m having some trouble creating this in the view. Is it ok for the view to have some logic in this case? I apologize in advance if this is a frequently asked question, I''m fairly new to programming and couldn''t find the right terminology for my search queries. Thank you in advance. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 19 April 2010 08:10, Ze Ca <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> In my form I have a select menu for US States. I would like to include > the capitals of those states as a hidden parameter when passed to the > model. Of course, the capital should match the state chosen.I don''t understand exactly what you are trying to do, here you say you want to pass this information to the model (did you mean controller). What has this got to do with a hidden field on the form.> > I know I can set a attr_accessor :state_capitals in the model, or even > make a migration to update the table and add the column, but I''m having > some trouble creating this in the view. Is it ok for the view to have > some logic in this case?Again I am unclear where this information is coming from and what you are trying to do with it. Perhaps you could explain in a little more detail what you are trying to accomplish. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote:> On 19 April 2010 08:10, Ze Ca <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> In my form I have a select menu for US States. I would like to include >> the capitals of those states as a hidden parameter when passed to the >> model. Of course, the capital should match the state chosen. > > I don''t understand exactly what you are trying to do, here you say you > want to pass this information to the model (did you mean controller). > What has this got to do with a hidden field on the form. > >> >> I know I can set a attr_accessor :state_capitals in the model, or even >> make a migration to update the table and add the column, but I''m having >> some trouble creating this in the view. Is it ok for the view to have >> some logic in this case? > > Again I am unclear where this information is coming from and what you > are trying to do with it. Perhaps you could explain in a little more > detail what you are trying to accomplish. > > ColinColin, Thank you for your reply. Yes, passing the information to the controller is what I meant (sorry about that!). This is just a toy project where I''d like to use the extra parameters (based on what the user enters) to "spit out" more information in the view. For example, If the user choses New York as their state and clicks submit, the resulting "show" view shows the user other information about the state they chose from the selector list (such as the capital). Thanks! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
If you know the states name, then you automatically know the capitals name, dont you? So then it wouldnt be necessary to submit the capital name as a hidden field, as you can retrieve it through the state object. Or am I missunderstanding something? On Apr 19, 3:40 pm, Ze Ca <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote: > > On 19 April 2010 08:10, Ze Ca <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> In my form I have a select menu for US States. I would like to include > >> the capitals of those states as a hidden parameter when passed to the > >> model. Of course, the capital should match the state chosen. > > > I don''t understand exactly what you are trying to do, here you say you > > want to pass this information to the model (did you mean controller). > > What has this got to do with a hidden field on the form. > > >> I know I can set a attr_accessor :state_capitals in the model, or even > >> make a migration to update the table and add the column, but I''m having > >> some trouble creating this in the view. Is it ok for the view to have > >> some logic in this case? > > > Again I am unclear where this information is coming from and what you > > are trying to do with it. Perhaps you could explain in a little more > > detail what you are trying to accomplish. > > > Colin > > Colin, > > Thank you for your reply. Yes, passing the information to the controller > is what I meant (sorry about that!). This is just a toy project where > I''d like to use the extra parameters (based on what the user enters) to > "spit out" more information in the view. For example, If the user choses > New York as their state and clicks submit, the resulting "show" view > shows the user other information about the state they chose from the > selector list (such as the capital). > > Thanks! > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sharagoz wrote:> If you know the states name, then you automatically know the capitals > name, dont you? > So then it wouldnt be necessary to submit the capital name as a hidden > field, as you can retrieve it through the state object. > Or am I missunderstanding something?Hi Sharagoz, Thanks for the reply! Yes, that is a possible solution, but this is just a toy project meant for learning about hidden form fields. I''m mainly curious what I could do with them. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Apr-19 16:25 UTC
Re: Re: associate hidden field with another field in a form
On 19 April 2010 15:32, Ze Ca <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Sharagoz wrote: >> If you know the states name, then you automatically know the capitals >> name, dont you? >> So then it wouldnt be necessary to submit the capital name as a hidden >> field, as you can retrieve it through the state object. >> Or am I missunderstanding something? > > Hi Sharagoz, > > Thanks for the reply! Yes, that is a possible solution, but this is just > a toy project meant for learning about hidden form fields. I''m mainly > curious what I could do with them.Anything you put in a hidden form field will be available in the params array in the controller. That is about it really. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote:> On 19 April 2010 15:32, Ze Ca <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> a toy project meant for learning about hidden form fields. I''m mainly >> curious what I could do with them. > > Anything you put in a hidden form field will be available in the > params array in the controller. That is about it really. > > ColinI appreciate the reply, however what I''m trying to figure out is if I could pass to the controller a specific parameter based on what the user selects in the form select menu. Basically have some logic in the form so that if I choose :state => "New York" from the select menu of states, the hidden field :state_capital => "Albany" will be passed along with it. I used formtastic to easily generate the hidden fields, but I''m having trouble with the logic. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You could just wrap the capital''s in a partial then put that in a hidden tag. On Apr 19, 2:10 am, Ze Ca <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> In my form I have a select menu for US States. I would like to include > the capitals of those states as a hidden parameter when passed to the > model. Of course, the capital should match the state chosen. > > I know I can set a attr_accessor :state_capitals in the model, or even > make a migration to update the table and add the column, but I''m having > some trouble creating this in the view. Is it ok for the view to have > some logic in this case? > > I apologize in advance if this is a frequently asked question, I''m > fairly new to programming and couldn''t find the right terminology for my > search queries. > > Thank you in advance. > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker
2010-Apr-19 19:46 UTC
Re: Re: associate hidden field with another field in a form
Ze Ca wrote:> Colin Law wrote: >> On 19 April 2010 15:32, Ze Ca <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> a toy project meant for learning about hidden form fields. I''m mainly >>> curious what I could do with them. >> >> Anything you put in a hidden form field will be available in the >> params array in the controller. That is about it really. >> >> Colin > > I appreciate the reply, however what I''m trying to figure out is if I > could pass to the controller a specific parameter based on what the user > selects in the form select menu. Basically have some logic in the form > so that if I choose :state => "New York" from the select menu of states, > the hidden field :state_capital => "Albany" will be passed along with > it. I used formtastic to easily generate the hidden fields, but I''m > having trouble with the logic.What several of the responses are trying to tell you is that what you''re attempting is pointless. If the server-side code can determine the state capital from the state name then there''s no point shoving that information into a hidden field. Just look it up server-side. HTML forms, once generated and sent to the client browser, are static. There is no interactions between form fields on the client-side. In order to add client-side interaction you need client-side scripting (generally JavaScript). In your case the JavaScript would need to know the state capitals by state name. In order to push that JavaScript to the client you need to send it to them from the server-side. Since in either case the sever-side already knows how to lookup state capitals from state names, putting that information into a hidden field is pointless. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.