Trying to learn if params can be modified

What I am trying to do is have the user enter a 2 digit birth year in
the view, then have the controller do it’s magic and get a 4 digit
date for the birthday. That part went fine, but now I’m having trouble
replacing the 2 digit year in params with the correct 4 digit value
before the create/update to the database. Please Help

Thanks

Bob

Bob S. wrote:

What I am trying to do is have the user enter a 2 digit birth year in
the view, then have the controller do it’s magic and get a 4 digit
date for the birthday.

That should probably be done in the model, not the controller.

That part went fine, but now I’m having trouble
replacing the 2 digit year in params with the correct 4 digit value
before the create/update to the database. Please Help

Just assign appropriately:
params[:birth_year] += 1900

Thanks

Bob

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Philip H. wrote:

That part went fine, but now I’m having trouble
replacing the 2 digit year in params with the correct 4 digit value
before the create/update to the database. Please Help

Just assign appropriately:
params[:birth_year] += 1900

Careful. My kid was born in 2004… not 1904. He probably won’t be
signing up on your website, but then again he recently admonished me
for not knowing about youtube playlists so you never know.

Better to check the 2 digits… if it’s less than 09 add 2000.
Otherwise add 1900. Of course that will tick off all your 100-yr old
users :slight_smile:

I’m aware of that, of course. This was meant to be a rudimentary
example, but thanks for stating explicitly what I was too lazy to! :slight_smile:

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

That part went fine, but now I’m having trouble
replacing the 2 digit year in params with the correct 4 digit value
before the create/update to the database. Please Help

Just assign appropriately:
params[:birth_year] += 1900

Careful. My kid was born in 2004… not 1904. He probably won’t be
signing up on your website, but then again he recently admonished me
for not knowing about youtube playlists so you never know.

Better to check the 2 digits… if it’s less than 09 add 2000.
Otherwise add 1900. Of course that will tick off all your 100-yr old
users :slight_smile: