Hi - I''m trying to understand the help for this: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000940 it says: select(object, method, choices, options = {}, html_options = {}) questions- 1) what is ''object'' ? Is this an ActiveRecord object? 2) what is method? 3) do i assume that my form object created from form_for calls select directly? 4) what is the form of object- is it "user", @user, user, or :user ? Please explain why, this is terribly confusing for a newbie. So, if I have a view: <% content_for(:page) do %> <h1>New user</h1> <% form_for :user, @user, :url => { :action => "create" } do |form| %> #NOTE I''M TRYING TO USE FORM_FOR <%= render :partial => ''form'', :locals => { :form => form, :genders => @genders, :user=>@user} %> #SEND THE FORM INSTANCE DOWN TO PARTIAL <%= submit_tag "Create" %> <%end%> <%end%> Notice I''m attempting to send the current user to the partial, I''m not sure if I''m doing this right. Also, my controller created a User instance (@user) which I''m sending to the partial. and the partial: <p> <label> Last Name<br/> <%= form.text_field :lastname %> </label> </p> ... <p> <label> Gender<br/> <%= form.select(''user'', "gender", {"Male" => 1, "Female" =>2 })%> #THIS DOESN''T WORK </label> </p> Note, there is no gender table, just 2 choices. User has a gender field which is an integer. So all I''m trying to do is let the client choose a gender from a select box. Please tell me what I''m doing wrong and if possible, answer my questions above. Thanks, Dino --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 27 Feb 2008, at 13:24, dino d. wrote:> > Hi - > > I''m trying to understand the help for this: > > http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000940 > > it says: > > select(object, method, choices, options = {}, html_options = {}) > > questions- > > 1) what is ''object'' ? Is this an ActiveRecord object? > 2) what is method? > 3) do i assume that my form object created from form_for calls select > directly? > 4) what is the form of object- is it "user", @user, user, or :user ? > Please explain why, this is terribly confusing for a newbie. >1) it''s ''user'' or :user. rails will look for an instance variable with that name 2) it''s the name method returning the value to display. This could be a db column or a computed property. form_for makes things a bit easier: when using form_for you don''t need to specify object (since that is setup in the call to form_for) ie you can do form.select(:gender, ...) (in the same way that you can do form.text_field :lastname) Fred> > So, if I have a view: > > <% content_for(:page) do %> > <h1>New user</h1> > <% form_for :user, @user, :url => { :action => "create" } do |form| > %> #NOTE I''M TRYING TO USE FORM_FOR > <%= render :partial => ''form'', :locals => { :form => form, :genders => > @genders, :user=>@user} %> #SEND THE FORM INSTANCE DOWN TO PARTIAL > <%= submit_tag "Create" %> > <%end%> > <%end%> > > Notice I''m attempting to send the current user to the partial, I''m not > sure if I''m doing this right. Also, my controller created a User > instance (@user) which I''m sending to the partial. > > and the partial: > > <p> > <label> > Last Name<br/> > <%= form.text_field :lastname %> > </label> > </p> > ... > > <p> > <label> > Gender<br/> > <%= form.select(''user'', "gender", {"Male" => 1, "Female" =>2 })%> > #THIS DOESN''T WORK > </label> > </p> > > Note, there is no gender table, just 2 choices. User has a gender > field which is an integer. > > So all I''m trying to do is let the client choose a gender from a > select box. Please tell me what I''m doing wrong and if possible, > answer my questions above. > > > Thanks, > Dino > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> form_for makes things a bit easier: when using form_for you don''t need > to specify object (since that is setup in the call to form_for) <==============> ie you can do form.select(:gender, ...) (in the same way that you can > do form.text_field :lastname) > > Fred >OOOH!!!! Now i get it. Thanks for the great response. The docs are just not newbie friendly. Dino --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---