Safe data migrations
ruby script/plugin installand apply it in your migration:http://svn.remvee.net/plugins/safe_data_migrations
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.
Object.send :remove_const, :User rescue nil class User < ActiveRecord::Base; endNow 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!
amsterdam.rb
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
Voor rubyenrails.nl heb ik een artikel geschreven over mongrel handlers: Rails MVC aan je laars lappen met Mongrel handlers.
ActiveForm plugin
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:Installation:
- making forms which don’t needed storage, like simple email forms
- provide extra validations on existing ActiveRecord models
- make forms for composite objects
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
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
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
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!
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
Voor rubyenrails.nl heb ik een introductie tot camping geschreven: Proto Prototype.