ggrillone
ggrillone

Reputation: 526

Rails 3: Uninitialized constant in Controller?

I am following ryan bate's video: http://railscasts.com/episodes/340-datatables?view=comments, to learn how to connect the jquery datatables plugin to the server side to speed up the page load time. I am using Rails 3.

I am getting this weird error and I'm not sure what it means:

"NameError (uninitialized constant ReportsController::ReportsDatatable):
 app/controllers/reports_controller.rb:20:in `block (2 levels) in index'
 app/controllers/reports_controller.rb:18:in `index'"

It's especially strange because sometimes I get the error and other times I do not. I usually occurs when the table first loads, or (when the page does load) when I try to go to the next page..

Inside my reports controller:

class ReportsController < ApplicationController
  def index
    respond_to do |format|
      format.html
      format.json { render json: ReportsDatatable.new(view_context) }
    end
  end
end

Any ideas?

Thanks

Upvotes: 1

Views: 1416

Answers (1)

Erez Rabih
Erez Rabih

Reputation: 15788

Try to use :: to go to global namespace:

  format.json { render json: ::ReportsDatatable.new(view_context) }

Upvotes: 5

Related Questions