Help with FormOptionsHelper

Hi -

I’m trying to understand the help for this:

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 %>

New user

<% 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:

Last Name
<%= form.text_field :lastname %>

...

Gender
<%= form.select('user', "gender", {"Male" => 1, "Female" =>2 })%> #THIS DOESN'T WORK

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

On 27 Feb 2008, at 13:24, dino d. wrote:

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

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