Forum: Ruby on Rails activeresource issue - Rails 2.2

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
erik (Guest)
on 2009-05-10 07:07
(Received via mailing list)
I'm doing something like this in a simple test script:
show_cc = CreditCard.find(account.credit_card_ref, :params => {:salt
=> salt})
unless show_cc.errors.nil? or show_cc.errors.empty?
    puts "we gots errors : #{show_cc.errors.to_yaml}"
    exit
end
puts "show card : #{show_cc.to_yaml}"

show_cc.credit_card_month = '12'
show_cc.iv = salt
show_cc.cvv = '999'
show_cc.save
unless show_cc.errors.nil? or show_cc.errors.empty?
    puts "we gots errors : #{show_cc.errors.to_yaml}"
    exit
end

puts "updated card : #{show_cc.to_yaml}

CreditCard is a n ActiveResource class.  The show_cc.save is done as a
create instead of an update.  I figured since the show_cc object is
first created from a find (show) and then i modify the attributes and
do a save I should get an update.

I'm on Rails 2.2.
Thanks.
Erik
erik (Guest)
on 2009-05-10 07:36
(Received via mailing list)
So if found this code in the activeresource code:
active_resource/base.rb:      new? ? create : update

so a cc.new? if true would call create, and sure enough it is.  Anyone
know why getting something from a find would make the object as new?
Thanks.
Erik
erik (Guest)
on 2009-05-10 07:45
(Received via mailing list)
Just in-case anyone else runs into this...if you have an object
without an id, it's new.
here is the code
def new?  #line 704 in active_resource/base.rb
  d.nil?
end

I was removing the id for a decent reason, but it looks like i'm going
to need to come up with something else.
Erik
This topic is locked and can not be replied to.