Merge branch 'api' of https://github.com/ZeusWPI/Tab into api
This commit is contained in:
commit
786e0a8d01
2 changed files with 19 additions and 11 deletions
|
@ -13,27 +13,33 @@ class TransactionsController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
@transaction = Transaction.new(set_params.merge(origin: I18n.t('origin.created_by_user')))
|
||||
|
||||
if @transaction.save
|
||||
respond_to do |format|
|
||||
format.html { redirect_to root_path }
|
||||
format.json { head :created }
|
||||
@transaction = Transaction.new(transaction_params)
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
if @transaction.save
|
||||
flash[:success] = "Transaction created"
|
||||
redirect_to new_transaction_path
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
format.json do
|
||||
head(@transaction.save ? :created : :unprocessable_entity)
|
||||
end
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_params
|
||||
def transaction_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
|
||||
creditor: User.find_by(name: t[:creditor]) || User.zeus,
|
||||
issuer: current_client || current_user
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,5 +7,7 @@
|
|||
= javascript_include_tag 'application', 'data-turbolinks-track' => true
|
||||
= csrf_meta_tags
|
||||
%body
|
||||
= content_tag :div, flash[:alert] if flash[:alert]
|
||||
- flash.each do |key, value|
|
||||
.alert{ :class => "alert-#{key}" }
|
||||
= value
|
||||
= yield
|
||||
|
|
Loading…
Reference in a new issue