fix transactions cretate

This commit is contained in:
Ilion Beyst 2015-09-09 13:33:55 +02:00
parent c3bf2b74cc
commit 3d8b1e9c60
2 changed files with 19 additions and 11 deletions

View file

@ -8,27 +8,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

View file

@ -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