Merge branch 'api' of https://github.com/ZeusWPI/Tab into api

This commit is contained in:
benji 2015-09-09 14:08:42 +02:00
commit 786e0a8d01
2 changed files with 19 additions and 11 deletions

View file

@ -13,27 +13,33 @@ class TransactionsController < ApplicationController
end end
def create def create
@transaction = Transaction.new(set_params.merge(origin: I18n.t('origin.created_by_user'))) @transaction = Transaction.new(transaction_params)
respond_to do |format|
if @transaction.save format.html do
respond_to do |format| if @transaction.save
format.html { redirect_to root_path } flash[:success] = "Transaction created"
format.json { head :created } redirect_to new_transaction_path
else
render 'new'
end
end
format.json do
head(@transaction.save ? :created : :unprocessable_entity)
end end
else
render 'new'
end end
end end
private private
def set_params def transaction_params
t = params.require(:transaction) t = params.require(:transaction)
.permit(:debtor, :creditor, :amount, :message) .permit(:debtor, :creditor, :amount, :message)
t.update({ t.update({
debtor: User.find_by(name: t[:debtor]) || User.zeus, debtor: User.find_by(name: t[:debtor]) || User.zeus,
creditor: User.find_by(name: t[:creditor]) || User.zeus creditor: User.find_by(name: t[:creditor]) || User.zeus,
issuer: current_client || current_user
}) })
end end
end end

View file

@ -7,5 +7,7 @@
= javascript_include_tag 'application', 'data-turbolinks-track' => true = javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags = csrf_meta_tags
%body %body
= content_tag :div, flash[:alert] if flash[:alert] - flash.each do |key, value|
.alert{ :class => "alert-#{key}" }
= value
= yield = yield