I've encountered some problems with MongoID. I have three models:
require 'mongoid'
class Configuration
include Mongoid::Document
belongs_to :user
field :links, :type => Array
field :root, :type => String
field :objects, :type => Array
field :categories, :type => Array
has_many :entries
end
class TimeDim
include Mongoid::Document
field :day, :type => Integer
field :month, :type => Integer
field :year, :type => Integer
field :day_of_week, :type => Integer
field :minute, :type => Integer
field :hour, :type => Integer
has_many :entries
end
class Entry
include Mongoid::Document
belongs_to :configuration
belongs_to :time_dim
field :category, :type => String
# any other dynamic fields
end
Creating documents for Configurations and TimeDims is successful. But when i've trying to execute following code:
params = Hash.new
params[:configuration] = config # an instance of Configuration from DB
entry.each do |key, value|
params[key.to_sym] = value # String
end
unless Entry.exists?(conditions: params)
params[:time_dim] = self.generate_time_dim # an instance of TimeDim from DB
params[:category] = self.detect_category(descr) # String
Entry.new(params).save
end
... i saw following output:
/home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/bson-1.6.1/lib/bson/bson_c.rb:24:in `serialize': Cannot serialize an object of class Configuration into BSON. (BSON::InvalidDocument)
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/bson-1.6.1/lib/bson/bson_c.rb:24:in `serialize'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongo-1.6.1/lib/mongo/cursor.rb:604:in `construct_query_message'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongo-1.6.1/lib/mongo/cursor.rb:465:in `send_initial_query'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongo-1.6.1/lib/mongo/cursor.rb:458:in `refresh'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongo-1.6.1/lib/mongo/cursor.rb:128:in `next'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongo-1.6.1/lib/mongo/db.rb:509:in `command'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongo-1.6.1/lib/mongo/cursor.rb:191:in `count'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/cursor.rb:42:in `block in count'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/collections/retry.rb:29:in `retry_on_connection_failure'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/cursor.rb:41:in `count'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/contexts/mongo.rb:93:in `count'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/criteria.rb:45:in `count'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/finders.rb:60:in `exists?'
from /home/scepion1d/Workspace/RubyMine/dana-x/crawler/crawler.rb:110:in `block (2 levels) in push_entries_to_db'
from /home/scepion1d/Workspace/RubyMine/dana-x/crawler/crawler.rb:103:in `each'
from /home/scepion1d/Workspace/RubyMine/dana-x/crawler/crawler.rb:103:in `block in push_entries_to_db'
from /home/scepion1d/Workspace/RubyMine/dana-x/crawler/crawler.rb:102:in `each'
from /home/scepion1d/Workspace/RubyMine/dana-x/crawler/crawler.rb:102:in `push_entries_to_db'
from main_starter.rb:15:in `<main>'
Can anyone tell what am I doing wrong?
Mongoid doesn't support the Mass assignment with Mongoid::Document. You need all the time pass by some Hash.
If you have define an accepts_nested_attributes_for on this relation you can override it by using a attr_attributes params.
This behavior is the same that ActiveRecord.
Related
To keep track of unique views I added impressionist gem. The impressions table will grow at a faster rate due to higher traffic. This will cause problems later when I want to show a comparison between consecutive weeks/months.
So I thought of linking impression's model with solr.
To implement this I first created a model named impression under app/models/impression.rb folder.
class Impression < ActiveRecord::Base
attr_accessible :user_id, :ip_address, :action_name, :controller_name, :impressionable_type, :impressionable_id, :view_name, :session_hash, :message, :request_hash, :referrer
searchable :ignore_attribute_changes_of => [ :updated_at] do
text :message, :boost=> 2.0
text :referrer
text :ip_address
integer :user_id
time :created_at
time :updated_at
string :message
string :view_name
string :ip_address
string :impressionable_type
string :controller_name
string :action_name
string :session_hash
string :request_hash
integer :id
integer :impressionable_id
end
end
Then I viewed few blogposts where impressionist was implemented and then did solr reindexing.
bundle exec rake sunspot:reindex[,Impression]
[###########################################################################################################] [4/4] [100.00%] [00:00] [00:00] [2.78/s]
# This did the reindexing.
Next I tried using solr to query Impression model.
search = Sunspot.search Impression do
with(:impressionable_type).equal_to('Blogpost')
with(:impressionable_id).equal_to(1)
end.total
puts "total results #{search || 0}"
search
The above code keeps throwing this error:
undefined method `field' for nil:NilClass
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/dsl/standard_query.rb:112:in `with'
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:241:in `__proxy_method__'
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:236:in `method_missing'
from (irb):8:in `block in irb_binding'
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:208:in `instance_eval'
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:208:in `instance_eval_with_context'
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/util.rb:86:in `instance_eval_or_call'
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/search/abstract_search.rb:202:in `build'
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/session.rb:50:in `new_search'
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/session.rb:58:in `search'
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `search'
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-queue-0.10.2/lib/sunspot/queue/session_proxy.rb:62:in `search'
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/sunspot-2.1.0/lib/sunspot.rb:345:in `search'
from (irb):8
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/railties-3.2.14/lib/rails/commands/console.rb:47:in `start'
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/railties-3.2.14/lib/rails/commands/console.rb:8:in `start'
from /home/xyz/.rvm/gems/ruby-2.1.0/gems/railties-3.2.14/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
Can anyone tell me how can I create a Impression model for using it with solr?
Fixed this by adding the same model definitions under config/initializers/impressionist_patch.rb:
class Impression < ActiveRecord::Base
attr_accessible :user_id, :ip_address, :action_name, :controller_name, :impressionable_type, :impressionable_id, :view_name, :session_hash, :message, :request_hash, :referrer
searchable :ignore_attribute_changes_of => [ :updated_at] do
text :message, :boost=> 2.0
text :referrer
text :ip_address
integer :user_id
time :created_at
time :updated_at
string :message
string :view_name
string :ip_address
string :impressionable_type
string :controller_name
string :action_name
string :session_hash
string :request_hash
integer :id
integer :impressionable_id
end
end
And I was able to define my own class and instance methods within this file.
ArgumentError: wrong number of arguments (1 for 0)
from /Users/Castillo/Desktop/gainer/app/models/status.rb:13:in `update_remaining_nutrients'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/associations/collection_association.rb:507:in `block in callback'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/associations/collection_association.rb:504:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/associations/collection_association.rb:504:in `callback'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/associations/collection_association.rb:352:in `add_to_target'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/associations/collection_association.rb:495:in `block in concat_records'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/associations/collection_association.rb:493:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/associations/collection_association.rb:493:in `concat_records'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/associations/collection_association.rb:134:in `block in concat'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/associations/collection_association.rb:149:in `block in transaction'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/transactions.rb:208:in `transaction'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/associations/collection_association.rb:148:in `transaction'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/associations/collection_association.rb:134:in `concat'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-3.2.11/lib/active_record/associations/collection_proxy.rb:116:in `<<'
from /Users/Castillo/Desktop/gainer/app/models/user.rb:65:in `eat'
from (irb):31
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
I want to call the update_remaining_nutrients method on status.rb whenever a meal is "eaten" by the user. When I call User.first.eat(Meal.first) I get the ArgumentError. Not sure why because I'm not passing the after_add method any arguments?
user.rb
class User < ActiveRecord::Base
has_many :meals
has_many :statuses
def eat(meal)
statuses.last.meals<<meal
end
end
status.rb
class Status < ActiveRecord::Base
attr_accessible :remaining_calories, :remaining_carbs, :remaining_protein, :weight, :user_id
belongs_to :user
has_many :meals, after_add: :update_remaining_nutrients
after_save :update_users_weight , :if => Proc.new {|a| a.weight_changed?}
def update_users_weight
self.user.weight.update_attributes(weight: self.weight)
end
def update_remaining_nutrients
puts "It Works!!!!!"
end
end
meal.rb
class Meal < ActiveRecord::Base
attr_accessible :name, :description, :clean_up, :homemade, :prep_time, :user_id, :status_id
belongs_to :user
belongs_to :status
has_many :ingredient_meals
has_many :ingredients, :through => :ingredient_meals
end
If you have a look at the Association callbacks section of the docs, you'll see this example:
class Project
has_and_belongs_to_many :developers, after_add: :evaluate_velocity
def evaluate_velocity(developer)
...
end
end
That's not the has_many relationship that you have but it is close enough. If you look at the evaluate_velocity method, you'll see that the developer in question is passed as an argument by the :after_add callback. You're getting an ArgumentError about your update_remaining_nutrients being called with one argument when it doesn't want any and that matches what the the example suggests would happen.
Try this:
def update_remaining_nutrients(meal)
# Do interesting things with `meal` in here...
end
here's my code:
init file:
require 'sequel'
DB = Sequel.connect('sqlite://data.db')
DB.drop_table?(:restaurants)
DB.create_table :restaurants do
primary_key :id
String :name
end
DB.drop_table?(:category)
DB.create_table :category do
primary_key :id
String :name
end
DB.drop_table?(:items)
DB.create_table :items do
primary_key :id
foreign_key :restaurant_id
foreign_key :category_name
String :name
Float :price
end
require_relative './restaurant'
require_relative './categories'
require_relative './item'
app file:
require_relative './models/init
p = Category.create(:name => 'Pizza')
c = Category.create(:name => 'Calazone')
pa = Category.create(:name => 'Pasta')
s = Category.create(:name => 'Salad')
d = Category.create(:name => 'Dessert')
dr = Category.create(:name => 'Drink')
si = Category.create(:name => 'Side')`
But I am getting this error:
/home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:1780:in `block in set_restricted': method name= doesn't exist (Sequel::Error)
from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:1767:in `each'
from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:1767:in `set_restricted'
from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:1278:in `set'
from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:1736:in `initialize_set'
from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:920:in `initialize'
from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:156:in `new'
from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:156:in `create'
from app.rb:4:in `<main>'"
Help Please.
Thanks
You don't post your Category model, but I'm guessing it's not actually looking at the category table (probably the categories table). You either want to rename your database table to categories or tell your Category model to use the category table. If that's not it, you probably want to post your model code.
I have the following mongoid model that inherits from the Entry model:
class Entry::Twitter < Entry
field :retweet_count, :type => Integer, :default => 0
field :retweeted, :type => Boolean, :default => false
field :favorited, :type => Boolean, :default => false
# in_reply_to_screen_name, in_reply_to_status_id_str, in_reply_to_user_id_str
field :reply, :type => Hash
field :from, :type => Hash # user: id_str, name, screen_name
field :time, :type => Time # created_at
field :data, :type => Hash # entities (hashtags and user_mentions)
field :assets, :type => Hash # urls from original entities
field :service, :type => String, :default => "twitter"
attr_accessible :assets
# validations
validates_presence_of :retweet_count, :from, :time, :data
# override set_service cause of https://github.com/sferik/twitter/issues/303
def set_service
self.service = "twitter"
end
end
When i try to reference it i get the following warning:
ruby-1.9.3-p125 :001 > Entry::Twitter
(irb):1: warning: toplevel constant Twitter referenced by Entry::Twitter
=> Twitter
Instead of referencing to my model it references to the Top Level Constant Twitter that is defined by a gem.
What can i do to fix this? I don't want to use another name for my class.
here is the solution:
https://github.com/rails/rails/issues/6931
I just added require_dependency 'entry/twitter' to every files that references Entry::Twitter to avoid this problem, and it works fine now.
I encountered the following problem with MongoID.
I've created two models which related by one to many.
require 'mongoid'
class User
include Mongoid::Document
has_many :configs
field :login, :type => String, unique: true
field :password, :type => String
field :email, :type => String
end
class Config
include Mongoid::Document
belongs_to :user
field :links, :type => Array
field :root, :type => Array
field :objects, :type => Array
field :categories, :type => Array
end
After that I've created new User instance:
user = User.new
user.login = "login1"
user.password = "password1"
user.email = "email1"
user.save
But I saw the following output:
/home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/inflector/methods.rb:229: Use RbConfig instead of obsolete and deprecated Config.
/home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/relations/referenced/many.rb:550:in `criteria': undefined method `where' for RbConfig:Module (NoMethodError)
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/relations/metadata.rb:143:in `criteria'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/relations/builders/referenced/many.rb:20:in `build'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/relations/accessors.rb:43:in `create_relation'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/relations/accessors.rb:26:in `build'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/relations/accessors.rb:101:in `block (4 levels) in getter'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/threaded/lifecycle.rb:125:in `_loading'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/relations/accessors.rb:100:in `block (3 levels) in getter'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/threaded/lifecycle.rb:84:in `_building'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/relations/accessors.rb:99:in `block (2 levels) in getter'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/validations.rb:51:in `read_attribute_for_validation'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activemodel-3.2.2/lib/active_model/validator.rb:151:in `block in validate'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activemodel-3.2.2/lib/active_model/validator.rb:150:in `each'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activemodel-3.2.2/lib/active_model/validator.rb:150:in `validate'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:310:in `_callback_before_1'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:407:in `_run__852778899__validate__1039643020__callbacks'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:405:in `__run_callback'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:385:in `_run_validate_callbacks'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/callbacks.rb:43:in `run_callbacks'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activemodel-3.2.2/lib/active_model/validations.rb:212:in `run_validations!'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activemodel-3.2.2/lib/active_model/validations/callbacks.rb:53:in `block in run_validations!'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:403:in `_run__852778899__validation__1039643020__callbacks'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:405:in `__run_callback'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:385:in `_run_validation_callbacks'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/callbacks.rb:43:in `run_callbacks'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activemodel-3.2.2/lib/active_model/validations/callbacks.rb:53:in `run_validations!'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activemodel-3.2.2/lib/active_model/validations.rb:179:in `valid?'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/validations.rb:75:in `valid?'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/activemodel-3.2.2/lib/active_model/validations.rb:187:in `invalid?'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/persistence/insertion.rb:23:in `block in prepare'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/persistence/insertion.rb:22:in `tap'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/persistence/insertion.rb:22:in `prepare'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/persistence/operations/insert.rb:26:in `persist'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/persistence.rb:49:in `insert'
from /home/scepion1d/Workspace/RubyMine/dana-x/.bundle/ruby/1.9.1/gems/mongoid-2.4.6/lib/mongoid/persistence.rb:154:in `upsert'
from parser/parsing_starter.rb:47:in `<main>'
If I remove the lines with "has_many" and "belongs_to" then the program will work correctly.
Can anyone tell what am I doing wrong?
Looks like there's some kind of collision with your Config class and one that might already be defined. Try changing the name of the model to something like UserConfig.
Or you can use a wrapper module to namespace your classes:
module MyApp
class Config
...
end
class User
...
end
end