Move datatables to seperate controller and provide user#show api

This commit is contained in:
benji 2015-09-17 16:46:33 +02:00
parent 41970612b2
commit cbf491e49c
4 changed files with 19 additions and 8 deletions

View file

@ -0,0 +1,9 @@
class DatatablesController < ApplicationController
respond_to :json
def transactions_for_user
user = User.find(params[:id])
datatable = DataTable.new(user, params)
render json: datatable.json
end
end

View file

@ -1,16 +1,16 @@
class UsersController < ApplicationController
skip_before_filter :verify_authenticity_token, only: :create
before_action :authenticate_user!, except: :show
before_action :authenticate_user_or_client!, only: :show
load_and_authorize_resource
def show
@user = User.find(params[:id])
respond_to do |format|
format.html do
@transaction = Transaction.new
end
format.json do
datatable = DataTable.new(@user, params)
render json: datatable.json
end
format.html { @transaction = Transaction.new }
format.json { render json: @user }
end
end

View file

@ -53,7 +53,7 @@
%input.live-updating.value-thing{type: 'text', placeholder: 'Filter on Message',
class: "form-control" }
%table#transactions.pure-table.pure-table-striped{data: { source: user_path(@user) }}
%table#transactions.pure-table.pure-table-striped{data: { source: user_transactions_path(@user) }}
%thead
%tr
%th Time

View file

@ -7,4 +7,6 @@ Rails.application.routes.draw do
resources :transactions, only: [:index, :create]
resources :users, only: [:show, :index]
get 'datatables/:id' => 'datatables#transactions_for_user', as: "user_transactions"
end