Setting my paid_until_date

Why doesnt this work…it’s not setting my paid_until_date.

VIEW CODE

Paid until <%= date_select ‘property’, ‘paid_until_date’, :order =>
[:day, :month, :year] %>

CONTROLLER ACTION

def record_payment
@property = Property.find(params[:id])
Property.find(params[:id]).payments.create(params[:payment])
@property.update_attribute(:paid_until_date,
params[:paid_until_date])

# puts @property.property_name
# redirect_to :action => 'list_all_properties'   <-- WORKS !
redirect_to :action => 'manage_payments', :id => @property

end

PARAMS PASSED FROM LOG

Parameters: {“commit”=>“Record Payment”,
“property”=>{“paid_until_date(1i)”=>“2008”, “paid_until_date(2i)”=>“1”,
“paid_until_date(3i)”=>“12”}, “action”=>“record_payment”, “id”=>“1”,
“payment”=>{“paid_on(1i)”=>“2008”, “paid_on(2i)”=>“1”,
“amount”=>“22222”, “note”=>"", “paid_on(3i)”=>“12”},
“controller”=>“admin”}

EXTRACT OF UPDATE LINE IN LOG…

Property Update (0.000624) UPDATE properties SET property_name =
‘Rupes Place’, paid_until_date = NULL <---- why NULL ?

driving me a bit mad, any kind person help me out ? I think i am close ?

bb

any ideas?

On 1/12/08, bingo bob [email protected] wrote:

CONTROLLER ACTION

def record_payment
@property = Property.find(params[:id])
Property.find(params[:id]).payments.create(params[:payment])
@property.update_attribute(:paid_until_date,
params[:paid_until_date])

Have a close look at those parameters you listed below. I think this
last line should be
@property.update_attribute(:paid_until_date,
params[:property][:paid_until_date])

EXTRACT OF UPDATE LINE IN LOG…


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

The passed params should be the same, as only the controller code was
modified. If you notice:

Parameters : { … “property”=>{“paid_until_date(…)”=>“…”, … } }

Because you’re using date_select, it splits the value into 3 and
reassembles it later into params[:property][:paid_until_date]

If you’d like to see what your controller is using, try adding a “puts
params.inspect” or “puts params[:property].inspect”.

You can also try to update with:

@property.update_attributes(params[:property])

On Jan 12, 8:58 am, bingo bob [email protected]

thanks but still no dice…with the new line?

here are the passed params…

Parameters: {“commit”=>“Record Payment”,
“property”=>{“paid_until_date(1i)”=>“2011”, “paid_until_date(2i)”=>“1”,
“paid_until_date(3i)”=>“12”}, “action”=>“record_payment”, “id”=>“1”,
“payment”=>{“paid_on(1i)”=>“2008”, “paid_on(2i)”=>“1”, “amount”=>“444”,
“note”=>"", “paid_on(3i)”=>“12”}, “controller”=>“admin”}

On Jan 12, 2008, at 6:13 AM, bingo bob wrote:

def record_payment
@property = Property.find(params[:id])
Property.find(params[:id]).payments.create(params[:payment])
@property.update_attribute(:paid_until_date,
params[:paid_until_date])

This won’t solve your problem, but why are you doing the find twice?
Why not make the create line be
@property.payments.create(params[:payment])