Tag Archives: ruby

[rubygems] handling SSL errors on Windows when installing gems

When you encounter SSL errors when installing gems on Windows, the easiest workaround is to change your sources from https://… to http://…. But … I am an avid user/fan of rails-assets.org and today I suddenly started getting the error on their domain. So at first I feared that rails-assets had stopped as foreseen (in this […]

[oracle] avoiding SLOW sdo_aggr_union

There is this recurring problem we have in GIS: getting road-segments and wanting to show complete roads. The naive approach would we to do something like the following: insert into street_geoms select ro.rd_ro_ident, ro.rd_ro_name, ro.com_code, ssdo_aggr_union(sdoaggrtype(rd.ro_geometry, 0.005)) as geom from rd_road ro, rd_ro_sec ros where ros.rd_ro_ident = ro.rd_ro_ident group by ro.rd_ro_ident, ro.rd_ro_name, ro.com_code; For good […]

Using render-anywhere gem with partials

Normally in rails, you can only render views inside of the controller. But what if you want to render a view somewhere else? For instance we wanted to generate xml-files using views. Haml can be used to describe xml just as well as plain html. There is a gem called render_anywhere that allows just that. […]

[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, […]