Problem with date object

Hello All,

My problem is i have field “expiry_date” which is a “date” type.
I want to take that date and store it in database as following

in controller

def create

  cc_information = params[:credit_card]
  @credit_card = CreditCard.new
  @credit_card.first_name = cc_information['first_name']
  @credit_card.last_name = cc_information['last_name']
  @credit_card.cc_number = cc_information['cc_number']
  .........
  .........

  @credit_card.expiry_date =

Date.civil(cc_information[‘expiry_date(1i)’],
cc_information[‘expiry_date(2i)’], cc_information[‘expiry_date(3i)’])

end

I can use this also @credit_card = CreditCard.new(params[:credit_card])

But I don’t want it. I want to store “expiry_date” using Date.civil or
Date.civil_to_jd

but it throws me error

ArgumentError in Credit cardsController#create

comparison of String with 0 failed

RAILS_ROOT: D:/subscription_manegement
Application Trace | Framework Trace | Full Trace

c:/ruby/lib/ruby/1.8/date.rb:596:in <' c:/ruby/lib/ruby/1.8/date.rb:596:invalid_civil?’
c:/ruby/lib/ruby/1.8/date.rb:726:in civil' D:/subscription_manegement/app/controllers/credit_cards_controller.rb:52:increate’

In view new.html.erb

<% form_for :credit_card, @credit_card, :url => credit_cards_path, :html
=>{:method => :post} do |f| %>
<%= f.error_messages %>


… other fields

<%= f.label :expiry_date %>
<%= f.date_select :expiry_date %>

please tell me Where I am doing wrong?

Thanks,
Vikas

On Jun 10, 8:39 am, Vikas G. [email protected]
wrote:

I can use this also @credit_card = CreditCard.new(params[:credit_card])

But I don’t want it. I want to store “expiry_date” using Date.civil or
Date.civil_to_jd

why not let activerecord do the hard work for you ? Anywway, the
problem here is that you need to turn those strings into integers
before giving them to Date.civil.

Fred

Let active record do the work for you. Put in a
before_validation_on_create (or update or whatever) hook in your model
and do the changes you want. Also, isn’t Date.civil the same as the
normal date convention we use?

On Jun 10, 12:39 pm, Vikas G. [email protected]

Frederick C. wrote:

On Jun 10, 8:39�am, Vikas G. [email protected]
wrote:

I can use this also @credit_card = CreditCard.new(params[:credit_card])

But I don’t want it. I want to store “expiry_date” using Date.civil or
Date.civil_to_jd

why not let activerecord do the hard work for you ? Anywway, the
problem here is that you need to turn those strings into integers
before giving them to Date.civil.

Fred

Thanks Fred, i didn’t use to_i method to convert string to integer.

Ryan B. wrote:

Just FYI:

It is illegal to store credit card information from your users
(without proper clearance from certain authorities). Check out the PCI
standard.

That is a recommendation. I don’t think it has the force of law – at
least in the US – but do check before you do anything stupid!

I recommend using a payment gateway like PaymentExpress.

Indeed.

Best,

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

Just FYI:

It is illegal to store credit card information from your users
(without proper clearance from certain authorities). Check out the PCI
standard.

I recommend using a payment gateway like PaymentExpress.