Activeresource issue - Rails 2.2

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

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

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs