Reputation: 459
I can't for the live of me get a consern to load in an app I'm building. I'm using this for server-side processing with datatables.
Just in case it's messing with something I'm including the structure of the module, where I have one general module with a bunch of stuff that is defined by specialized modules that have classes which include the general module. The intent being to use definitions inside the specialized classes for the different types of data found in different tables without having to repeat a bunch of code.
I haven't even gotten to the
The error:
ActionController::RoutingError (uninitialized constant MetatasksController::MetatasksDatatableModule):
app/controllers/metatasks_controller.rb:2:in `<class:MetatasksController>'
app/controllers/metatasks_controller.rb:1:in `<top (required)>'
My controller (/app/controllers/metatasks_controller.rb) has this:
class MetatasksController < ApplicationController
include MetatasksDatatableModule
[...]
end
The consern (/app/controllers/concerns/metatask_datatables_consern.rb) has this:
module MetatasksDatatableModule
extend ActiveSupport::Concern
class MetatasksDatatable
include DatatableModule
[...]
end
end
The generalized datatable module (/app/controllers/concerns/datatables_module.rb) has this:
module DatatableModule
included do
[...]
end
end
My autoload paths include the folder (edited for relevancy/privacy):
> rails r 'puts ActiveSupport::Dependencies.autoload_paths'
[...]
/home/<user>/sites/<appname>/app/controllers/concerns
[...]
Upvotes: 0
Views: 683
Reputation: 5690
It's quite likely that Rails can't autoload because the filenames don't match the module names, and so it doesn't know where to load them from.
So metatask_datatables_consern.rb
should be called metatasks_datatable_module.rb
and datatables_module.rb
should be datatable_module.rb
Upvotes: 1