2015-09-08 15:25:54 +02:00
|
|
|
class TransactionsController < ApplicationController
|
|
|
|
def index
|
2015-09-08 20:45:32 +02:00
|
|
|
@transactions = Transaction.all
|
2015-09-08 15:25:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@transaction = Transaction.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-09-09 12:58:44 +02:00
|
|
|
@transaction = Transaction.new(set_params.merge(origin: I18n.t('origin.created_by_user')))
|
2015-09-08 21:07:00 +02:00
|
|
|
|
|
|
|
if @transaction.save
|
2015-09-09 12:58:44 +02:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to root_path }
|
|
|
|
format.json { head :created }
|
|
|
|
end
|
2015-09-08 21:07:00 +02:00
|
|
|
else
|
|
|
|
render 'new'
|
|
|
|
end
|
2015-09-08 15:25:54 +02:00
|
|
|
end
|
|
|
|
|
2015-09-08 21:07:00 +02:00
|
|
|
private
|
|
|
|
|
2015-09-09 11:56:13 +02:00
|
|
|
def set_params
|
|
|
|
t = params.require(:transaction)
|
|
|
|
.permit(:debtor, :creditor, :amount, :message)
|
|
|
|
|
2015-09-09 12:58:44 +02:00
|
|
|
t.update({
|
2015-09-09 11:56:13 +02:00
|
|
|
debtor: User.find_by(name: t[:debtor]) || User.zeus,
|
|
|
|
creditor: User.find_by(name: t[:creditor]) || User.zeus
|
2015-09-09 12:58:44 +02:00
|
|
|
})
|
2015-09-08 21:07:00 +02:00
|
|
|
end
|
2015-09-08 15:25:54 +02:00
|
|
|
end
|