I also did the custom CC using ActiveAttr. Quite simple and no Rails
required for testing which I love :)

https://gist.github.com/4056448

Regards,
Dmytrii Nagirniak
http://ApproachE.com <http://www.ApproachE.com>


On 8 November 2012 09:50, Ivan Vanderbyl <[email protected]> wrote:

> Ah yes, I went through this same problem a few weeks ago with a CC form.
> Ended up doing the same thing.
>
>
> On 08/11/2012, at 9:46 AM, Steven Ringo <[email protected]> wrote:
>
>  Hi,
>
> @Ivan, thanks :-)
>
> Since this is a credit card field, we are going to just have separate
> explicit fields for month and year, as that's what the acquirer wants
> anyway.
>
> I was worried about how to handle validations on the combined date, but we
> don't need to validate at that level. Rather we validate for all the credit
> card fields together.
>
> Perhaps it might be a good idea to see multi-parameter attributes factored
> out of AR and into ActiveModel?
>
> Thanks again.
>
> Steve
>
> On Thursday, 8 November 2012 at 9:39 AM, Ivan Vanderbyl wrote:
>
> Hi Steve,
>
> This is handled by ActiveRecord usually
> in ActiveRecord::AttributeAssignment#assign_multiparameter_attributes (
> https://github.com/rails/rails/blob/master/activerecord/lib/active_record/attribute_assignment.rb#L62-66
> )
>
> You could experiment with either mixing in that module or pulling out the
> #assign_multiparameter_attributes methods into your own module and using it
> with ActiveModel.
>
> AFAIK there is no equivalent for ActiveModel.
>
> — Ivan
>
> On 08/11/2012, at 8:55 AM, Steven Ringo <[email protected]> wrote:
>
> 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.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby or Rails Oceania" group.
> 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.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby or Rails Oceania" group.
> 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.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Ruby or Rails Oceania" group.
> 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.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
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