Skip to content

Commit

Permalink
Move datatables to seperate controller and provide user#show api
Browse files Browse the repository at this point in the history
  • Loading branch information
becousae committed Sep 17, 2015
1 parent 4197061 commit cbf491e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
9 changes: 9 additions & 0 deletions app/controllers/datatables_controller.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/views/users/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

resources :transactions, only: [:index, :create]
resources :users, only: [:show, :index]

get 'datatables/:id' => 'datatables#transactions_for_user', as: "user_transactions"
end

0 comments on commit cbf491e

Please sign in to comment.