module Stock
class CategoriesController < ApplicationController
include ::TheSortableTreeController::Rebuild
class Stock::Category < ActiveRecord::Base
acts_as_nested_set
include ::TheSortableTree::Scopes
This method form gem won't work
module DefineVariablesMethod
public
def the_define_common_variables
collection = self.class.to_s.split(':').last.sub(/Controller/,'').underscore.downcase # 'recipes'
collection = self.respond_to?(:sortable_collection) ? self.sortable_collection : collection # 'recipes'
variable = collection.singularize # 'recipe'
klass = self.respond_to?(:sortable_model) ? self.sortable_model : variable.classify.constantize # Recipe
["@#{variable}", collection, klass]
end
end
If I have namespaced controller and model
This method form gem won't work
Because this line
collection = self.class.to_s.split(':').last.sub(/Controller/,'').underscore.downcase
Will result "categories"
And here
klass = self.respond_to?(:sortable_model) ? self.sortable_model : variable.classify.constantize
you will get error
*** NameError Exception: uninitialized constant Category
Because the class is not Category but Stock::Category