Using association properties in form helpers

sorry for the noob question:

how do i reference an association’s properties in a form helper?

e.g. if i wanted to build a select list to choose a user’s address’s
state (user.address.state), how would i hook that to the “method” of
collection_select
collection_select :user, ???, States.find(:all)

jeff emminger wrote:

sorry for the noob question:

how do i reference an association’s properties in a form helper?

e.g. if i wanted to build a select list to choose a user’s address’s
state (user.address.state), how would i hook that to the “method” of
collection_select
collection_select :user, ???, States.find(:all)

No, you can’t do that directly at present, though a core patch
is available to allow cascades such as this to be used in form
helpers: http://dev.rubyonrails.org/ticket/2053

Instead you need to write:

Controller:

for new:

 @user = User.new(params[:user])
 @address = @user.build_address(params[:address])

or for edit:

 @user = User.find(params[:id])
 @address = @user.address
 @address.attributes = params[:address]

View:

collection_select :address, :state, …


We develop, watch us RoR, in numbers too big to ignore.

awesome - thanks for the reply. i kind of figured out the same answer
but it’s good to hear reinforcement. makes for a bit of a mess in the
update method unfortunately.

that core patch - is it going to be made a part of a future release
e.g. RoR 1.7 or something?