“...I've been working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix and learning Rust. I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it. Currently working for InPay...”

Rob Lacey (contact@robl.me)
Senior Software Engineer, Brighton, UK

Rails Way - Das magazin fur Ruby on Rails

I found this little gem in a bog standard boring, run of the mill newsagents in Berlin, Zoologischer Garten. Perhaps Germany is more tech friendly but having monthly Ruby on Rails, PHP, .Net and Java monthlies is is quite crazy for what would be a small readership.

Available at http://it-republik.de/railsway/magazin-ausgaben/Ruby-on-Rails-000281.html

Git remote branches

Nice little and verbose script to aid with the creation of remote git repos.

http://blog.carlmercier.com/2008/01/25/no-nonsense-git-part-1-git-remote-branch/

git-remote-branch create sv1.8

or to track an already existing remote branch

git branch --track sv1.8 origin/sv1.8

IEH8

Why does IE8 ignore this, grrrrrrrrr.

<!--[if lt IE 8]>
<script src="http://oursite.com/ie8.min.js" type="text/javascript"></script>
<![endif]-->

It seems that the ie8.js script doesn’t like being used inside a frame.
http://dean.edwards.name/weblog/2008/01/ie7-2/

Hi dean,

First of all great work. I have a problem when I use your script inside a frame (ugly, I know). I get a permission denied on ‘if(/ie7_off/.test(top.location.search)||k<5)’.

Any thoughts on a quick fix?

Thanks, Ronald Moolenaar

YAML defaults

I really do love the way you can add defaults in YAML

development: &defaults
  consumer_key: randomzombieaction
  consumer_secret: morerandomzombieaction
test: 
  <<: *defaults
staging:
  <<: *defaults
production:
  <<: *defaults

Stewie Vs Zombie

Who will win?

Donkey Kong Vs. Stewie

Who will win?

jQuery, Nano and Songkick

Knocked this one up earlier today to get my Songkick gig listings on this here blog. Maybe its just the novelty of having some gigs to go to and a bit of showing off that we’re running off to Germany for 11 days of mayhem and we’ve not learned how to speak the language yet.

$(document).ready(function () {

  var template = "<li><a href='{uri}'>{displayName}</a></li>";
  var apikey = '<your apikey>';
  var container = $("ul#concerts");

  $.getJSON('http://api.songkick.com/api/3.0/users/<your songkick username>/events.json?apikey=' + apikey + '&jsoncallback=?', function(data) {
    container.html("");
    events = data["resultsPage"]["results"]['event'];
    $.each(events.reverse(), function() {
      container.append($.nano(template, this));
    });
  });

});

Pledge Music Alpha Launch

Our new project Pledge Music went into Alpha just over a week ago and by all accounts its been a success.

“Pledge Music is a way for fans to help their favourite artists make records and raise money for charity. By combining new social networking technology, fan incentives and old school music biz know how, fans can visit the site to not only hear great new music, but also share the experience with friends and get actively involved in what they are listening to.”

We launched on two platforms Facebook and Pledge Music with our first project Another Last Goodbye by Marwood. The project aimed to raise $5000 in order record a CD with a percentage of the profits going to Amnesty International and met its target with 7 days of launch which we’re very pleased with.

Now we have a successful Alpha test, Marwood are entering the studio to record their album over the next few weeks and we look forward to hearing the album very soon.

Now the real work begins as we do a last push to move through Beta and into a full release over the next month with another 9 projects already in the pipeline. Go team.

Chef how to

http://wiki.opscode.com/display/chef/Home

Counter cache is now read only?

I recently added counter cache to one of my assocations to try and solve a validation problem. ie. If an object has too many associated objects already then it would be invalid.

Easy, set up counter cache and update your existing database with the current totals, however this doesn’t work anymore. It doesn’t set them at all.

Subscription.all.each do |s| 
  s.update_attribute :requirements_count, s.requirements.length
end

I can see all the updates in my log, but minus the ‘requirements_count’ which was the whole point :S

Requirement Load (0.9ms)   SELECT * FROM "requirements" WHERE ("requirements".subscription_id = 158) ORDER BY created_on asc
  Subscription Update (0.9ms)   UPDATE "subscriptions" SET "updated_on" = '2009-07-11 17:44:35.463992' WHERE "id" = 158
  Requirement Load (1.1ms)   SELECT * FROM "requirements" WHERE ("requirements".subscription_id = 264) ORDER BY created_on asc
  Subscription Update (0.9ms)   UPDATE "subscriptions" SET "updated_on" = '2009-07-11 17:44:35.470008' WHERE "id" = 264

I found this in the ActiveRecord changelog :( It states this is now a readonly field. Under normal circumstances I agree it should be readonly but what about when you just want to get your data into the right state?

*2.0.0 [Preview Release]* (September 29th, 2007) [Includes duplicates of changes from 1.14.2 - 1.15.3]

* Add attr_readonly to specify columns that are skipped during a normal ActiveRecord #save operation. Closes #6896 [Dan Manges]

  class Comment < ActiveRecord::Base
    # Automatically sets Article#comments_count as readonly.
    belongs_to :article, :counter_cache => :comments_count
  end

  class Article < ActiveRecord::Base
    attr_readonly :approved_comments_count
  end

The solution it seems is to redeclare the class you are trying update the count in in the migration class. I cut and pasted this from a mailing list post I found. This seems stupidly awkward a solution and took far too long to diagnose this problem.

class AddRequirementsCountToSubscriptions < ActiveRecord::Migration
 
  class Subscription < ActiveRecord::Base

    has_many :requirements

    def reset_column_information
      generated_methods.each {|name| undef_method(name) }
      @column_names = @columns = @columns_hash = @content_columns = @dynamic_methods_hash = @generated_methods = @inheritence_column = nil
    end
      
  end

  def self.up
    add_column :subscriptions, :requirements_count, :integer, :default => 0
    
    Subscription.reset_column_information

    Subscription.all.each do |s|
      puts "UPDATING #{s.id}"
      puts "#{s.requirements.length}"
      s.update_attribute :requirements_count, s.requirements.length
    end
  end

  def self.down
    remove_column :subscriptions, :requirements_count
  end

end

sigh