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:in `valid_civil?'' c:/ruby/lib/ruby/1.8/date.rb:726:in `civil'' D:/subscription_manegement/app/controllers/credit_cards_controller.rb:52:in `create'' ----------------------------------------------------------------------- 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 <p> <%= f.label :expiry_date %><br /> <%= f.date_select :expiry_date %> </p> please tell me Where I am doing wrong? Thanks, Vikas -- Posted via http://www.ruby-forum.com/.
On Jun 10, 8:39 am, Vikas Gholap <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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_jdwhy 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 Gholap <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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:in `valid_civil?'' > c:/ruby/lib/ruby/1.8/date.rb:726:in `civil'' > D:/subscription_manegement/app/controllers/credit_cards_controller.rb:52:in > `create'' > ----------------------------------------------------------------------- > > 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 > > <p> > <%= f.label :expiry_date %><br /> > <%= f.date_select :expiry_date %> > </p> > > please tell me Where I am doing wrong? > > Thanks, > Vikas > -- > Posted viahttp://www.ruby-forum.com/.
Frederick Cheung wrote:> On Jun 10, 8:39�am, Vikas Gholap <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt> > 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. > > FredThanks Fred, i didn''t use to_i method to convert string to integer. -- Posted via http://www.ruby-forum.com/.
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.
Ryan Bigg 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 marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.