tab/app/controllers/transactions_controller.rb
2015-09-09 11:56:13 +02:00

35 lines
749 B
Ruby

class TransactionsController < ApplicationController
skip_before_filter :verify_authenticity_token, :only => :create
def index
@transactions = Transaction.all
end
def new
@transaction = Transaction.new
end
def create
@transaction = current_user.outgoing_transactions.build(
transaction_params.merge(origin: I18n.t('origin.created_by_user'))
if @transaction.save
redirect_to current_user
else
render 'new'
end
end
private
def set_params
t = params.require(:transaction)
.permit(:debtor, :creditor, :amount, :message)
t.update {
debtor: User.find_by(name: t[:debtor]) || User.zeus,
creditor: User.find_by(name: t[:creditor]) || User.zeus
}
end
end