I’ve a mongoid model and method like the following :
class Category
include Mongoid::Document
field :name, :type => String
...
def self.custom_find
...
Str = Struct.new(:arg1, :arg2)
array << Str.new(one, two)
...
end
end
and I get the following error :
dynamic constant assignment (SyntaxError)
Str = Struct.new(:arg1, :arg2)
I tried moving Str = Struct.new(:arg1, :arg2) into config/initializers/categories.rb but then I get :
BSON::InvalidDocument in TrendsController#index
Cannot serialize an object of class Category into BSON.
by removing the custom_find offending method, everithing else works fine, then I guess is something related to "Struct".
Any idea ?
You can work around dynamic constant assignment error in several ways:
or
This shouldn’t solve serialization problem, though.