我在我的模型中的字段名爲isTransfer:軌布爾值重上創建
class AddTxfrColumnsToTransaction < ActiveRecord::Migration
def change
add_column :transactions, :isTransfer, :boolean
add_column :transactions, :transferAccount_id, :integer
end
end
我創建了一個控制器,它應該像動作:新的,但只是轉移呼叫new_transfer:
def new_transfer
account = Account.find(params[:account_id])
@transaction = account.transactions.build
@transaction.description = "Transfer"
@transaction.isTransfer = true
@transaction.amount = 100
respond_to do |format|
format.html # new.html.erb
format.json { render json: @transaction }
end
end
當我在我的視圖窗體中看到新的傳輸時,在發佈之前,我可以看到isTransfer設置爲true。但是當我發佈時,它總是作爲錯誤進入數據庫。其他領域(描述和數量)不會改變 - 他們按預期進行。
這裏是模型:
class Transaction < ActiveRecord::Base
attr_accessible :account_id, :amount, :check, :date, :description, :is_cleared, :note, :category, :isTransfer, :transferAccount_id
validates_presence_of :amount, :date
belongs_to :account, class_name: 'Account'
belongs_to :transferAccount, class_name: 'Account'
end
您可以在保存它的位置顯示您的操作? –
你在哪裏保存@transaction?使用@ transaction.save –
我相信保存發生在創建操作中。 – Cagilla