Add client identification methods

This commit is contained in:
Ilion Beyst 2015-09-09 11:31:34 +02:00
parent 1233431d14
commit 7423cb4dda
3 changed files with 15 additions and 2 deletions

View file

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

View file

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

View file

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