Tag Archives: ruby

[ruby] hate private methods? use protected instead

I started out writing something like the following: If I could change just one thing in ruby, I would change how private works. Aaarrgghh. For instance, I am trying to implement an equality of bounding boxes in ruby. I would presume I could write something like: class BoundingBox attr_accessor :xmin, :ymin, :xmax, :ymax def initialize(xmin, […]

[rails] store your settings in a model

Most of the times I use a config.yml to store application settings, that I want to be able to change quickly between environments, servers, deployments. But what with settings that need to be changed on the fly, by a user? I create a small model, with three fields. rails g model Setting name:string description:string value:string […]

Run rails 2.3.18 using ruby 1.8.7 on windows server 2012

For my current job we have two 2.3.5 rails sites, of which I already succesfully upgraded one to rails 4. For the other we still need to start the migration, and we were asked to install new windows servers to run the rails servers on in the meantime (let’s not digress why they choose windows, […]

Short and clean ruby (or an exercise in group-think)

In some part of my code I ended writing the following: where self is some ActiveRecord model, and count_processed is an attribute of that model (and stored in the database). What am i trying to achieve (if it is not blatantly obvious): if count_processed is not initialised, make it zero increment count_processed Imho this code […]

logging the activerecord-session-store

I had an issue where I was not sure the ActiveRecord::SessionStore was actually working (in hindsight: it worked). But to make sure, I needed to know what was stored in the session or retrieved. Now all logging for the session-store is silenced, using Base.silence. Now I was very interested in that logging, and did not […]

using jasmine without rails

Assume you have, like I did, a ruby gem that contains some javascript you want to test standalone. First you need to install the jasmine-gem. You have two options: either you use your gemspec to drive your bundler gemfile, so just add it to your developement dependencies I am still using jeweler, so I use […]

[mongoid] adding timestamps to an existing mongo collection

In our Rails 3 application we use mongo to store logging of critical actions. At first we did not store a separate timestamp, since the _id (which is a BSON::ObjectId contains a timestamp as well. Our model, simplified, looked like this: This is all fine and dandy, but when we wanted to build some reporting, […]

[mongoid] doing a group-by on date

Doing a simple group-by query using mongo and mongoid is actually pretty straightforward. According to the documentation, mongoid does not offer any group/aggregation function itself, but mongo does. And you can directly access the mongo using the collection. So assume we have a mongo collection: and now I want to count all occurrences of the […]

Porting an existing rails 2 site to rails 3

I have created a few rails 3 sites, but i have never before ported an existing rails2 application to rails3. I will describe the problems i encountered. First off there were some very good resources (step-by-step descriptions) to guide me through it: the rails_upgrade plugin The asciicast (readable) upgrading to rails3 part 1 and part […]

Arrrrcamp 29/10/2010

The fourth and most international of all arrrrcamp editions. Also the first paying edition. As i said in my post about the previous edition, i have been to all editions, and it is awesome to see how it has grown. The schedule was amazing, with an amazing array of international speakers, of which for me […]