Hi there,
this is my first message on a Google group so I hope I'm doing it right.
I'm building my first web application with Ruby, Sinatra and MongoMapper.
So far it's been going good, but now I've run into a very strange error when executing the following line:
@p = Parameter.all
With Parameter being this class:
class Parameter
include MongoMapper::Document
plugin MongoMapper::Plugins::IdentityMap
connection Mongo::Connection.new($_DB_SERVER_CNC)
set_database_name $DB_NAME
key :name, String
key :description, String
key :db, String
key :db_table, String
key :db_field, String
#key :compare, Array
#many :parameters, :in => :compare
key :created_by, String, :default => 'id833541'
timestamps!
end
The error here is:
NoMethodError: undefined method `collection' for nil:NilClass
And it happens inmongo_mapper-0.12.0/lib/mongo_mapper/plugins/persistence.rb
def collectionassert_supported
database.collection(collection_name) # ******HERE*******
end
The reason why I really don't understand how this could happen is that it works with another class that looks about the same:
class SettingCategory
include MongoMapper::Document
plugin MongoMapper::Plugins::IdentityMap
connection Mongo::Connection.new($_DB_SERVER_CNC)
set_database_name $_DB_NAME
key :name
key :description
key :created_by, String, :default => 'id833542'
timestamps!
many :settings
end
@sc = SettingCategory.all # works fine
I know I might not be giving a lot of info, including more on my application's structure, but I did my best to boil it down to the basics so you don't get extra clutter here. If you need anything else just let me know...
Thanks to anyone who could shed more light on the situation.