Registratie balie RubyEnRails2008 geopend!

Gepubliceerd op: 6.V.2008 20:31 CET
Categorieën: events, rails, ruby

Safe data migrations

Published at: 9.IV.2008 14:02 CET
Categories: plugin, rails
Comments: 4 pieces
Something ago I wrote about the problems which arise when using models in your Rails migrations. Meanwhile I developed a really simple solution to this problem and today I wrapped it up in to a plugin called SafeDataMigrations. How to use it? Install it in your Rails application:
ruby script/plugin install http://svn.remvee.net/plugins/safe_data_migrations
and apply it in your migration:
class DowncaseUserNames < ActiveRecord::Migration
  models :user

  def self.up
    User.find(:all).each do |user|
      user.update_attributes(:names, user.name.downcase)
    end
  end

Look at the README file for a more elaborate example.

So how does it work? It simply undefines the models your referring to and redefines an empty ActiveRecord class;
Object.send :remove_const, :User rescue nil
class User < ActiveRecord::Base; end
Now you are sure to have a User model available in your migration without any validations which may make data manipulations impossible. The undefining of an already available model also ensures you don’t need to use ActiveRecord::Base.reset_column_information before updating new fields, unless you use your model before altering the table of course.

Update: As coderrr points out you don’t need to clobber the global scope model class because a nested model works fine too. I wrongly assumed introducing a new model class in side (!) a migration class would only reopen my original model class and keep validations intact. To illustrate:

class User; def top; end; end

class Migration
  class User; def nested; end; end

  def self.go
    p User.instance_methods - Object.instance_methods
  end
end

Migration.go

yields ["nested"] and not ["top", "nested"] as I suspected. Apparently I was bitten too hard by a problem which arose when I used an original model class to even try the above. I’ll pull the plugin because it’s pointless.. Bad me, thanks coderrr!

Write a comment ››

amsterdam.rb

Gepubliceerd op: 17.I.2008 19:55 CET
Categorieën: events, rails, ruby
Reacties: 1 stuk

Op maandag 28 januari wordt de eerste amsterdam.rb bijeenkomst georganiseerd. Het idee is onder het genot van kop koffie ontstaan en leek, toen de cafeïne eenmaal uitgewerkt was, nog steeds een goed plan.

Komt allen rond 20u naar de bekeerde suster aan de nieuwmarkt om de geboorte van amsterdam.rb te vieren! Zegt het voort!

Mongrel handlers

Gepubliceerd op: 24.XII.2007 12:21 CET
Categorieën: mongrel, rails, ruby

Voor rubyenrails.nl heb ik een artikel geschreven over mongrel handlers: Rails MVC aan je laars lappen met Mongrel handlers.

ActiveForm plugin

Published at: 24.IX.2007 21:49 CET
Categories: active_form, english, plugin, rails
Comments: 2 pieces

Last week at RailsConf Europe I met some people who are using my ActiveForm code to make forms in their Rails sites. It’s about time to wrap it up as a plugin, so here it is.

From the README:
This plugin provides a base class for making forms with ActiveRecord validations without having a corresponding database table. You can use ActiveForm for:
  • making forms which don’t needed storage, like simple email forms
  • provide extra validations on existing ActiveRecord models
  • make forms for composite objects
Installation:
script/plugin install http://svn.remvee.net/plugins/active_form

I know, there already is a plugin called active_form but I don’t like it. It doesn’t provide a “real” AR object causing all kinds of things to not work (like ActiveRecordHelper#form and DateHelper#datetime_select for instance), it doesn’t include any tests and my version is a lot simpler (flog score 20 versus 74).

Why not change the name? I like it! If you can come up with something better, please leave a comment.

dutchify update voor Ruby 1.8.6

Gepubliceerd op: 9.IV.2007 17:27 CET
Categorieën: dutchify, plugin, rails, ruby
Reacties: 18 stuks
In Ruby 1.8.6 zijn er wat kleine verhuizingen met betrekking tot de Date class doorgevoerd, met als gevolg dat m’n hackwerk, ter vernederlandsing van datum formaten, applicaties, welke gebruik maken van de dutchify plugin, onklaar heeft gemaakt. In de nieuwste versie is dit probleem opgelost;
ruby script/plugin install --force http://svn.remvee.net/plugins/dutchify

Update probleem gevonden door Stephan gerepareerd, Time wel vertaald Date niet

Update 2 probleem gevonden door Bertus gerepareerd, date_select niet meer vertaald

Update 3 oeps, niet alle tests gedraaid.. Dank je Stephan.

RubyEnRails 2007

Gepubliceerd op: 8.III.2007 09:11 CET
Categorieën: events, rails, ruby

Er wordt hard gewerkt om voor eind mei, RubyEnRails 2007 te organiseren. Waarschijnlijk heb ik dit jaar geen waterdichte smoes. Zie je daar?

TDD met Ruby on Rails

Gepubliceerd op: 12.II.2007 11:44 CET
Categorieën: rails, ruby, testen

Op de Finalist Developers Blog kan je een artikel van mijn hand over Test Driven Development met Ruby on Rails lezen.

Reminder: JRuby talk tomorrow!

Published at: 18.XII.2006 10:44 CET
Categories: english, java, rails, ruby

Both JRuby super hero’s, Charles and Thomas, will be talking about JRuby tomorrow at Stroom Hotel in Rotterdam. Come and find out why having a Ruby interpreter on the Java platform is a “good thing”.

Registration seminar@finalist.com.

introductie tot camping

Gepubliceerd op: 5.X.2006 19:27 CET
Categorieën: camping, rails, ruby

Voor rubyenrails.nl heb ik een introductie tot camping geschreven: Proto Prototype.