Make create in transactions work

This commit is contained in:
benji 2015-09-09 12:58:44 +02:00
parent dbc533a1cb
commit 6229556e38
3 changed files with 9 additions and 7 deletions

View file

@ -10,11 +10,13 @@ class TransactionsController < ApplicationController
end
def create
@transaction = current_user.outgoing_transactions.build(
transaction_params.merge(origin: I18n.t('origin.created_by_user'))
@transaction = Transaction.new(set_params.merge(origin: I18n.t('origin.created_by_user')))
if @transaction.save
redirect_to current_user
respond_to do |format|
format.html { redirect_to root_path }
format.json { head :created }
end
else
render 'new'
end
@ -26,9 +28,9 @@ class TransactionsController < ApplicationController
t = params.require(:transaction)
.permit(:debtor, :creditor, :amount, :message)
t.update {
t.update({
debtor: User.find_by(name: t[:debtor]) || User.zeus,
creditor: User.find_by(name: t[:creditor]) || User.zeus
}
})
end
end

View file

@ -13,7 +13,6 @@ class Client < ActiveRecord::Base
before_create :generate_key
validates :name, presence: true, uniqueness: true
validates :key, presence: true, uniqueness: true
def transactions
Transaction.where(origin: name)

View file

@ -1,6 +1,7 @@
= @transaction.errors.full_messages.join(", ")
= simple_form_for @transaction do |f|
= f.collection_select :creditor_id, User.all, :id, :name, {}, { class: 'select2-selector' }
= f.hidden_field :debtor, value: current_user.name
= f.collection_select :creditor, User.all, :name, :name, {}, { class: 'select2-selector' }
= f.input :amount
= f.input :message, required: true
= f.submit "Send it!"