diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3ea39cf..16a8765 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,4 +6,15 @@ class ApplicationController < ActionController::Base rescue_from CanCan::AccessDenied do |exception| redirect_to root_url, alert: exception.message end + + def current_client + @current_client ||= identify_client + end + + private + + def identify_client + key = request.headers["X-API-KEY"] + Client.find_by key: key if key + end end diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb index ce60de4..5257ce8 100644 --- a/app/controllers/transactions_controller.rb +++ b/app/controllers/transactions_controller.rb @@ -1,4 +1,5 @@ class TransactionsController < ApplicationController + skip_before_filter :verify_authenticity_token, :only => :create def index @transactions = Transaction.all @@ -9,7 +10,8 @@ class TransactionsController < ApplicationController end def create - @transaction = current_user.outgoing_transactions.build transaction_params.merge(origin: I18n.t('origin.created_by_user')) + @transaction = current_user.outgoing_transactions.build( + transaction_params.merge(origin: I18n.t('origin.created_by_user')) if @transaction.save redirect_to current_user diff --git a/app/datatables/transaction_datatable.rb b/app/datatables/transaction_datatable.rb index 69ebfa3..3220a0d 100644 --- a/app/datatables/transaction_datatable.rb +++ b/app/datatables/transaction_datatable.rb @@ -2,7 +2,7 @@ class TransactionDatatable < AjaxDatatablesRails::Base include TransactionsHelper def sortable_columns - @sortable_columns ||= ['Transaction.amount'] + @sortable_columns ||= ['Transaction.created_at'] end def searchable_columns