2
1- account.rbRails的複式方法
class Account < ActiveRecord::Base
belongs_to :transaction
end
class Supplier < Account
end
class Expense < Account
end
2- transaction.rb
class Transaction < ActiveRecord::Base
has_many :accounts
accepts_nested_attributes_for :accounts
end
3-遷移模式
create_table "accounts", :force => true do |t|
t.string "name"
t.decimal "debit"
t.decimal "credit"
t.decimal "balance"
t.string "type"
t.integer "transaction_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "transactions", :force => true do |t|
t.string "name"
t.decimal "amount"
t.date "date"
t.string "document"
t.datetime "created_at"
t.datetime "updated_at"
end
end
問題1: 在視圖中達到供應商和費用的最佳方法是什麼(請參見下圖)?
問題2: 我如何能實現自動記錄expense_debit
和交易金額,反之亦然的方法? (View screenshot)
感謝您的回答Taryn East.I'm將嘗試您的解決方案。事實上,我從來沒有想過創建一個模型作爲交易和帳戶之間的鏈接。我希望帳戶傳輸模型將做的trick.I promess很快就會給你一個反饋。 – blawzoo