Rails Ajax Data in Production - DataTables Display No Data. Prod 200, Though Missing Components?

Rails Ajax Data in Production - DataTables Display No Data. Prod 200, Though Missing Components?

rgrant8rgrant8 Posts: 2Questions: 1Answers: 0
edited April 2016 in Free community support

I have searched high and low but have been unsuccessful in finding a solution to this problem. (Like many) I am using an Ajax call to populate the table and have modeled my DataTables.rb around the Railscast tutorial #340, with some subtle differences. For instance, I pass a string for the corresponding table name (database table), User ID, and the view_source (aka table id) for each of my three tables, depending on which one is being called. Quick mention, each table has it's own view so there are no ID issues here.. The Ajax response and calls are similar in the prod and dev logs. The tables are displaying and functioning flawlessly in Dev. Here is my code:

(Datatables Controller)

##### datatables.rb

def as_json(options = {})
{
sEcho: params[:sEcho].to_i,
iTotalRecords: @table.count,
iTotalDisplayRecords: market_datas.total_entries,
aaData: data
}
end

private

def data
market_datas.map do |market_data|
[
market_data.symbol,
market_data.name,
if @store[market_data.symbol] == true # assigns button title accordingly
link_to("Saved", market_data, id: "saved")
else
link_to("Explore", market_data)
end
]
end
end

def market_datas
@market_datas ||= fetch_market_datas
end

def fetch_market_datas
market_datas = @table.order("#{sort_column} #{sort_direction}") # assigns Market_data to @table
market_datas = market_datas.page(page).per_page(per_page)
if params[:sSearch].present?
market_datas = market_datas.where("symbol like :search or name like :search or sector like :search", search: "%#{params[:sSearch]}%")
end
market_datas
end

( Table Controller)

###### nyse.rb

def index
respond_to do |format|
format.html
if current_user
format.json { render json: StockDatatable.new(Nyse, view_context, current_user.id) }
else
format.json { render json: StockDatatable.new(Nyse, view_context, nil) }
end
end
end

( Partial View)

### _nyse.html.erb
">
Symbol Company Name Explore

<

script type="text/javascript">

$('#list_co').DataTable({
"lengthMenu": [[100, 250, 500, 5295], [100, 250, 500, "All"]],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": $('#list_co').data('source'),
"pagingType": "simple_numbers",
"pageLength": 250,
"order": [ 1, 'asc' ],
"scrollY": '425px',
"fixedHeader": true,
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': [ 2 ] },
],
"oLanguage": {
"sProcessing": "<img src='../assets/please_wait.gif' height='50' width='50'>"
},
"processing": true,
"bInfo" : false,
});

<

script>

#### application.js

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jquery.rails-ajax
//= require RailsAjax-Config
//= require dataTables/jquery.dataTables
//= require dataTables/extras/dataTables.responsive
...

#### application.css

*=_require jquery-ui
*= require dataTables/jquery.dataTables
*= require dataTables/extras/dataTables.responsive
...

#### production.rb

config.serve_static_assets = true
...

Dev Log

Started GET "/nyses.json?sEcho=1&iColumns=3&sColumns=%2C%2C&iDisplayStart=0&iDisplayLength=250&mDataProp_0=0&sSearch_0=&bRegex_0=false&bSearchable_0=true&bSortable_0=true&mDataProp_1=1&sSearch_1=&bRegex_1=false&bSearchable_1=true&bSortable_1=true&mDataProp_2=2&sSearch_2=&bRegex_2=false&bSearchable_2=true&bSortable_2=false&sSearch=&bRegex=false&iSortCol_0=1&sSortDir_0=asc&iSortingCols=1&=1461022905645" for 127.0.0.1 at 2016-04-18 16:41:47 -0700
Processing by NysesController#index as JSON
Parameters: {"sEcho"=>"1", "iColumns"=>"3", "sColumns"=>",,", "iDisplayStart"=>"0", "iDisplayLength"=>"250", "mDataProp_0"=>"0", "sSearch_0"=>"", "bRegex_0"=>"false", "bSearchable_0"=>"true", "bSortable_0"=>"true", "mDataProp_1"=>"1", "sSearch_1"=>"", "bRegex_1"=>"false", "bSearchable_1"=>"true", "bSortable_1"=>"true", "mDataProp_2"=>"2", "sSearch_2"=>"", "bRegex_2"=>"false", "bSearchable_2"=>"true", "bSortable_2"=>"false", "sSearch"=>"", "bRegex"=>"false", "iSortCol_0"=>"1", "sSortDir_0"=>"asc", "iSortingCols"=>"1", "
"=>"1461022905645"}
[1m[35mStockUserList Load (0.2ms)[0m SELECT "stock_user_lists".* FROM "stock_user_lists" WHERE (users_id = NULL)
[1m[36m (1.0ms)[0m [1mSELECT COUNT() FROM "nyses"[0m
[1m[35mCACHE (0.0ms)[0m SELECT COUNT(
) FROM "nyses"
[1m[36mNyse Load (7.5ms)[0m [1mSELECT "nyses".* FROM "nyses" ORDER BY name asc LIMIT 250 OFFSET 0[0m
Completed 200 OK in 119ms (Views: 76.1ms | ActiveRecord: 9.3ms)

Prod Log

I, [2016-04-18T16:27:57.189419 #818] INFO -- : Started GET "/nyses" for 127.0.0.1 at 2016-04-18 16:27:57 -0700
I, [2016-04-18T16:27:57.190256 #818] INFO -- : Processing by NysesController#index as HTML
I, [2016-04-18T16:27:57.191849 #818] INFO -- : Rendered nyses/nyses.html.erb (0.5ms)
I, [2016-04-18T16:27:57.191999 #818] INFO -- : Rendered nyses/index.html.erb within layouts/application (0.7ms)
I, [2016-04-18T16:27:57.193559 #818] INFO -- : Rendered devise/menu/_login_items.html.erb (0.3ms)
I, [2016-04-18T16:27:57.193833 #818] INFO -- : Rendered devise/menu/_registration_items.html.erb (0.2ms)
I, [2016-04-18T16:27:57.193991 #818] INFO -- : Rendered devise/menu/_message_items.html.erb (0.0ms)
I, [2016-04-18T16:27:57.194329 #818] INFO -- : Completed 200 OK in 4ms (Views: 3.1ms | ActiveRecord: 0.0ms)
I, [2016-04-18T16:27:57.743724 #818] INFO -- : Started GET "/nyses.json?sEcho=1&iColumns=3&sColumns=%2C%2C&iDisplayStart=0&iDisplayLength=250&mDataProp_0=0&sSearch_0=&bRegex_0=false&bSearchable_0=true&bSortable_0=true&mDataProp_1=1&sSearch_1=&bRegex_1=false&bSearchable_1=true&bSortable_1=true&mDataProp_2=2&sSearch_2=&bRegex_2=false&bSearchable_2=true&bSortable_2=false&sSearch=&bRegex=false&iSortCol_0=1&sSortDir_0=asc&iSortingCols=1&
=1461022077429" for 127.0.0.1 at 2016-04-18 16:27:57 -0700
I, [2016-04-18T16:27:57.744930 #818] INFO -- : Processing by NysesController#index as JSON
I, [2016-04-18T16:27:57.745001 #818] INFO -- : Parameters: {"sEcho"=>"1", "iColumns"=>"3", "sColumns"=>",,", "iDisplayStart"=>"0", "iDisplayLength"=>"250", "mDataProp_0"=>"0", "sSearch_0"=>"", "bRegex_0"=>"false", "bSearchable_0"=>"true", "bSortable_0"=>"true", "mDataProp_1"=>"1", "sSearch_1"=>"", "bRegex_1"=>"false", "bSearchable_1"=>"true", "bSortable_1"=>"true", "mDataProp_2"=>"2", "sSearch_2"=>"", "bRegex_2"=>"false", "bSearchable_2"=>"true", "bSortable_2"=>"false", "sSearch"=>"", "bRegex"=>"false", "iSortCol_0"=>"1", "sSortDir_0"=>"asc", "iSortingCols"=>"1", "_"=>"1461022077429"}
I, [2016-04-18T16:27:57.747881 #818] INFO -- : Completed 200 OK in 3ms (Views: 1.2ms | ActiveRecord: 0.4ms)

I should mention that I have precompiled the assets with no errors. I do see that I have some differences but many similarities in the logs. It seems to me like it is working ok, but I am not super experienced with deciphering the logs. Can anybody on here help figure out what I need to do to get these tables to populate correctly in Prod? I have tried just about everything I could find or think of for this problem and have had no luck at all. I can’t pinpoint what the actual problem is here.. Therefore, I can’t figure out what the correct solution is. Many Thanks!!

Answers

  • rgrant8rgrant8 Posts: 2Questions: 1Answers: 0

    As you can see from my logs, the database was not being called in Production.. So this ended up not being a datatables problem at all. It was a simple database error. I copied (migrated) the correct data to Prod and all is working great!!

This discussion has been closed.