From cbf491e49ce8758bfa5e85900373be0485928a69 Mon Sep 17 00:00:00 2001 From: benji Date: Thu, 17 Sep 2015 16:46:33 +0200 Subject: [PATCH] Move datatables to seperate controller and provide user#show api --- app/controllers/datatables_controller.rb | 9 +++++++++ app/controllers/users_controller.rb | 14 +++++++------- app/views/users/show.html.haml | 2 +- config/routes.rb | 2 ++ 4 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 app/controllers/datatables_controller.rb diff --git a/app/controllers/datatables_controller.rb b/app/controllers/datatables_controller.rb new file mode 100644 index 0000000..c93accd --- /dev/null +++ b/app/controllers/datatables_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f3da447..b111188 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 3b3d73d..3f9b130 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 1a3c572..e4d543e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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