When/where does Rails convert "params" used to populate a model object
from a form, into their correct types in the model object??? (i.e.
from "string") What part of rails does this?
I have a form upload and in my create method where I go
:@graph_options = GraphOptions.new(params[:graph_options])" it is not
doing the type conversion, as the attributes remain as strings.
When/where does Rails convert "params" used to populate a model object
from a form, into their correct types in the model object??? (i.e.
from "string") What part of rails does this?
Well it's the call to column.typecast here:
Which is defined here:
(but possibly overriden by individual connection adapters).
How that interacts with BaseWithoutTable I have no idea.
thanks - I'll have a look at the code - so would it be correct to say
then that the Rails framework does effectively cast the params strings
to their type prior to any saves to the data? (i.e. its not like it
leave this up to the database to do itself is it, i.e. like if there
was a date it doesn't just pass the string representation of the data
through to the database to store in it's Date field)
thanks - I'll have a look at the code - so would it be correct to say
then that the Rails framework does effectively cast the params strings
to their type prior to any saves to the data? (i.e. its not like it
leave this up to the database to do itself is it, i.e. like if there
was a date it doesn't just pass the string representation of the data
through to the database to store in it's Date field)
Actually it doesn't (minor exception in that a blank string is turned
into nil for numbers). typecasting happens in read_attribute (check
the source for read/write_attribute.