From c1563980c4b52afee1d0ca08188e91946f9b2db1 Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Tue, 8 Sep 2015 16:53:43 +0200 Subject: [PATCH 1/2] show names in the creditor selection dropdown --- app/views/transactions/new.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/transactions/new.html.haml b/app/views/transactions/new.html.haml index e1e2a52..94b2670 100644 --- a/app/views/transactions/new.html.haml +++ b/app/views/transactions/new.html.haml @@ -1,4 +1,4 @@ = form_for @transaction do |f| - = f.select :creditor, User.all, {}, { class: 'select2-selector' } + = f.collection_select :creditor, User.all, :id, :name, {}, { class: 'select2-selector' } = f.number_field :amount = f.submit "Send it!" From 363c825e55f9bc046e0e8d804418d423c6f3d84e Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Tue, 8 Sep 2015 17:30:02 +0200 Subject: [PATCH 2/2] add create controller and dummy view --- app/controllers/transactions_controller.rb | 4 ++++ app/views/transactions/create.html.haml | 17 +++++++++++++++++ config/locales/en.yml | 4 +++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 app/views/transactions/create.html.haml diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb index afbe1fa..a8e008e 100644 --- a/app/controllers/transactions_controller.rb +++ b/app/controllers/transactions_controller.rb @@ -9,6 +9,10 @@ class TransactionsController < ApplicationController end def create + creditor = User.find params.require(:transaction).require(:creditor) + debtor = current_user + amount = params.require(:transaction).require(:amount) + @transaction = Transaction.create debtor: debtor, creditor: creditor, amount: amount, origin: I18n.t('origin.created_by_user'), message: "Transaction by #{debtor.name} to #{creditor.name}" end end diff --git a/app/views/transactions/create.html.haml b/app/views/transactions/create.html.haml new file mode 100644 index 0000000..fa9cbf4 --- /dev/null +++ b/app/views/transactions/create.html.haml @@ -0,0 +1,17 @@ +%table + %tbody + %tr + %th Debtor + %td= @transaction.debtor.name + %tr + %th Creditor + %td= @transaction.creditor.name + %tr + %th Amount + %td= @transaction.amount + %tr + %th Origin + %td= @transaction.origin + %tr + %th Message + %td= @transaction.message diff --git a/config/locales/en.yml b/config/locales/en.yml index 0653957..6450dbe 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -20,4 +20,6 @@ # available at http://guides.rubyonrails.org/i18n.html. en: - hello: "Hello world" + origin: + created_by_user: "User" +