Overriding default id in mongoid

This is an easy one, just want to make sure it’s clear. Add the following field to your model: field :_id, type: Moped::BSON::ObjectId And to allow setting it: 1 def id=(id) 2 self[:_id] = id 3 end Now you can just do obj.id=[Some ObjectId] and save the object.

November 15, 2014 · 1 min · Chen Kinnrot

Rails + Mongo + Heroku how?

After a few hours of fighting with google I decided to write it all here: *This post is more relevant for windows users but can help others. What do you need to have: First you need to have ruby 1.9.2+ Devkit then you need rails 3+ then u need the bundler gem then go to getting started with mongoid then install mongo locally then check it all good then add account in heroku then create app then add your key then push

March 28, 2012 · 1 min · Chen Kinnrot

MVC Frameworks and dynamic languages

Warning! just figure out a mistake that can happen to every other programmer, and even brogrammers. I defined a method on my model that has the same name as one of the field of the model, because I used a dynamic language (ruby on rails) it was pretty hard to understand this issue (took me more than 1 hour). So a little tip: When thinking about names of actions and fields of your model, work with conventions and guidelines like: Don’t name your fields after action names!!! that’s it.

September 27, 2011 · 1 min · Chen Kinnrot