fix transactions cretate
This commit is contained in:
parent
c3bf2b74cc
commit
3d8b1e9c60
2 changed files with 19 additions and 11 deletions
|
@ -8,27 +8,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)
|
||||||
|
|
||||||
if @transaction.save
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to root_path }
|
format.html do
|
||||||
format.json { head :created }
|
if @transaction.save
|
||||||
end
|
flash[:success] = "Transaction created"
|
||||||
|
redirect_to new_transaction_path
|
||||||
else
|
else
|
||||||
render 'new'
|
render 'new'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
format.json do
|
||||||
|
head(@transaction.save ? :created : :unprocessable_entity)
|
||||||
|
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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue