Hi all,

Anyone have any idea on the best way to parse a date from a rails form and 
coerce it into a date field in an active model object.

Rails send this in the params hash:

 "credit_card_expiry(3i)"=>"1",
 "credit_card_expiry(2i)"=>"11",
 "credit_card_expiry(1i)"=>"2012"


However the model sees these as being three separate attributes, and of 
course the the active model object has no way of knowing this.

I have seen techniques that manually mangle the hash like so (or 
introspective variants), but this feels very hacky.

params[:subscription][:credit_card_expiry] = 
Date.new(params[:subscription][:"credit_card_expiry(1i)"].to_i,                 
                                           
params[:subscription][:"credit_card_expiry(2i)"].to_i, 
params[:subscription][:"credit_card_expiry(3i)"].to_i)

params[:subscription].delete(:"credit_card_expiry(1i)")
params[:subscription].delete(:"credit_card_expiry(2i)")
params[:subscription].delete(:"credit_card_expiry(3i)")


Thanks,

Steve

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rails-oceania/-/5N1Kll4oUZ4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to