title: Rails uninitialized constant when instantiating class
body: <p>I have created a new class in my Rails application under a folder structure of app/datatables</p>
  
  <p>The class is saved in a file in this directory and it is saved as DatasetIndexDatatable.rb</p>
  
  <p>The contents of the class file is as follows:</p>
  
  <pre><code>class DatasetIndexDatatable
    delegate :params, :h, :link_to, :number_to_currency, to: :@view
  
    def initialize(view)
      @view = view
    end
  
  end
  </code></pre>
  
  <p>When I try to instantiate this class from a controller in my application, Rails gives an error:</p>
  
  <pre><code>uninitialized constant DatadescriptionController::DatasetIndexDatatable
  </code></pre>
  
  <p>The code in the controller which attempts to instantiate the new class is as follows:</p>
  
  <pre><code>class DatadescriptionController &lt; ApplicationController
    layout "datadescription"
  
    def index
  respond_to do |format|
          format.html
          format.json { render json: DatasetIndexDatatable.new(view_context) }
      end
    end
  
  end
  </code></pre>
  
  <p>Why can't Rails see the new class?  I have tried adding the folder containing the class to the config.autoload_paths variable in application.rb:</p>
  
  <pre><code>config.autoload_paths += %W(#{config.root}/lib
                              #{config.root}/datatables)
  </code></pre>
  
  <p>but the same error occurs.  I have also tried instantiating the new class in the controller using the global namespace:</p>
  
  <pre><code>format.json { render json: ::DatasetIndexDatatable.new(view_context) }
  </code></pre>
  
  <p>and using the containing folder for the class as a namespace:</p>
  
  <pre><code>format.json { render json: Datatables::DatasetIndexDatatable.new(view_context) }
  </code></pre>
  
  <p>all to no avail.  What am I doing wrong?</p>