Hi,

I have a model for which when I go to save an item it doesn't seem to get
saved.  In the console I don't get a "record not saved" error???  But rather
the response seems to give me back a Transaction object (i.e. for which the
saved Allocation object has a relationship with)?  Any ideas why?

CONSOLE OUTPUT
?> a = Allocation.new
=> #<Allocation id: nil, transaction_id: nil, person_id: nil, recurring_id:
nil, amount: nil, amount_percent: nil, created_at: nil, updated_at: nil>
>> a.valid?
=> false
>> a.transaction_id = 1784
=> 1784
>> a.person_id = 1
=> 1
>> a.amount = 100
=> 100
>> a.valid?
=> true
>> a.save!
=> #<Transaction id: 1784, transaction_date: "2009-02-04", bank_account_id:
5, category_id: 6, recurring_id: 3, amount:
#<BigDecimal:22291e0,'0.0',4(8)>, balance:
#<BigDecimal:2229190,'0.1E4',4(12)>, description: "food", notes: nil,
created_at: "2008-12-08 21:21:17", updated_at: "2008-12-08 21:21:17",
projection: true>
>> a
=> #<Allocation id: nil, transaction_id: 1784, person_id: 1, recurring_id:
nil, amount: #<BigDecimal:2218160,'0.1E3',4(8)>, amount_percent: nil,
created_at: nil, updated_at: nil>
>>

MODEL
-----------------------------------------------------------------------------------------------------------------------
Macintosh-2:myequity greg$ cat app/models/allocation.rb
# == Schema Information
# Schema version: 20081128104846
#
# Table name: allocations
#
#  id             :integer(4)      not null, primary key
#  transaction_id :integer(4)      not null
#  person_id      :integer(4)      not null
#  recurring_id   :integer(4)
#  amount         :decimal(9, 2)
#  amount_percent :decimal(9, 2)
#  created_at     :datetime
#  updated_at     :datetime
#

class Allocation < ActiveRecord::Base
 belongs_to :person
 belongs_to :transaction

 validates_numericality_of :amount, :if => :amount
 validates_numericality_of :amount_percent, :if => :amount_percent

 private

 def validate
   errors.add_to_base('amount and amount_percent can not both be specified')
if amount && amount_percent
   errors.add_to_base('either amount OR amount_percent must be specified')
if !amount && !amount_percent
 end

end
-----------------------------------------------------------------------------------------------------------------------

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to