# Type cast after attributes=

**URL:** <https://www.ruby-forum.com/t/type-cast-after-attributes/91903>\
**Category:** Rails\
**Created:** [April 13, 2007, 8:41am UTC](https://www.ruby-forum.com/t/type-cast-after-attributes/91903 "2007-04-13T08:41:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dweinand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f17d59/32.png) [@dweinand](https://www.ruby-forum.com/u/dweinand)\
**Post date:** [April 13, 2007, 8:41am UTC](https://www.ruby-forum.com/t/type-cast-after-attributes/91903/1 "2007-04-13T08:41:55Z")

</div>

Hello,  
i have a problem with setting attributes.

Read from the DB. This attribut exists, fieldtype in DB is timestamp  
(PostgreSQL):  
“uebergabe\_datum”=\>“2007-04-03 10:32:00”

setting the attributes in controller with params=  
objekt.attributes = params[:my\_params]

results in this:  
“uebergabe\_datum”=\>#\<DateTime: 441754909/180,0,2299161\>

Everything like expected.

But there’s a case where the field “uebergabe\_datum” isn’t in the  
params hash.  
objekt.attributes isnt’t casting the attribut, cause it isn’t  
available.

loaded:  
“uebergabe\_datum”=\>“2007-04-03 10:32:00”

after attributes=:  
“uebergabe\_datum”=\>“2007-04-03 10:32:00”

with this value i’m not able to save the record.

how to get this: “uebergabe\_datum”=\>#\<DateTime:  
441754909/180,0,2299161\>  
without the attribut in the params? i’m looking for something like  
objekt.cast\_for\_db

regards
