mbulat/plutus — Issue #3: What'is the best way to implement transaction#create controller
Author: blawzoo
Created: 2011-11-30 23:07:06+00:00
State: open

Hello I'm running into big troubles right now.(please be indulgent, I'm not a seasoned rails coder)

1-When I create a account, everything works perfectly.

2-But when it comes to create a transaction, that's when things get tricky.Here's is the code:

def create

@transaction = Transaction.new(params[:transaction])
@transaction.credit_account = Account.where(:type => params[:type]).where(:name => params[:name])
@transaction.debit_account = Account.where(:type => params[:type]).where(:name => params[:name])

respond_to do |format|
if @transaction.save
format.html { redirect_to @transaction, :notice => 'Facture was successfully created.' }
else
format.html { render :action => "new" }
end
end
end

But when I hit submit i get the following message:

>ActiveRecord::AssociationTypeMismatch in TransactionsController#create
>Account(#2178411460) expected, got String(#2151988680)

If the method is wrong can anyone tell me please, the best way to write this controller?