From 3d8b1e9c602fa02062307aa0c299d3fc9ffdf6e5 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Wed, 9 Sep 2015 13:33:55 +0200 Subject: [PATCH] fix transactions cretate --- app/controllers/transactions_controller.rb | 26 +++++++++++++--------- app/views/layouts/application.html.haml | 4 +++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb index 72128f6..bf3ba5f 100644 --- a/app/controllers/transactions_controller.rb +++ b/app/controllers/transactions_controller.rb @@ -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 diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 41f8d44..20d7dea 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -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