I have a field in my model called isTransfer:
class AddTxfrColumnsToTransaction < ActiveRecord::Migration
def change
add_column :transactions, :isTransfer, :boolean
add_column :transactions, :transferAccount_id, :integer
end
end
I create a controller that should act like action: :new, but only for a transfer call 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
When I see the new transfer in my view form, before posting, I can see that isTransfer is set to true. But when I post, it always goes into the DB as false. The other fields (description and amount) do not change - they go in as expected.
Here is the model:
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