Upload Progress met Rails en Mongrel

Gepubliceerd op: 14.X.2008 22:02 CEST
Categorieën: javascript, mongrel, plugin, rails

Upload progress is lastig; aan de server kant bijhouden wat de voortgang is en gerommel met JavaScript om dat dan weer aan de gebruiker te kunnen tonen. Eigenlijk zou een browser dit zelf voor je moeten doen — bij een download kan ik toch ook zien hoe ver ik ben — maar helaas is de realiteit anders. Gebruikers van je applicaties opschepen met een “hangende” browsers als zij een paar fototjes uploaden is natuurlijk geen optie.

Gelukkig ben ik niet de enige met dit probleem en kan ik, omdat ik mijn applicaties met Mongrel deploy, gebruik maken van de Mongrel Upload Progress plugin. Vol enthousiasme heb ik me dan ook op deze plugin gestort maar heb na het lezen van de instructies met een vies gezicht een stapje terug genomen.

Lees verder →

Plugins naar Github

Gepubliceerd op: 3.IX.2008 13:13 CEST
Categorieën: active_form, dutchify, git, plugin, rails
Reacties: 6 stuks

In blinde opruimwoede heb ik m’n huis plugins op GitHub gezet.

  • ActiveForm; zie ook active_form
    ruby script/plugin install git://github.com/remvee/active_form.git
  • Dutchify; zie ook dutchify
    ruby script/plugin install git://github.com/remvee/dutchify.git
  • Labelify; Yet Another Form Builder
    ruby script/plugin install git://github.com/remvee/labelify.git
  • NullableBooleans; boolean attributen gemakkelijker op nil zetten
    ruby script/plugin install git://github.com/remvee/nullable_booleans.git

Safe data migrations

Published at: 9.IV.2008 05:02 CEST
Categories: english, 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!

ActiveForm plugin

Published at: 24.IX.2007 12:49 CEST
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 08:27 CEST
Categorieën: dutchify, plugin, rails, ruby
Reacties: 17 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.

dutchify plugin

Gepubliceerd op: 28.VIII.2006 09:28 CEST
Categorieën: dutchify, plugin, rails
Reacties: 20 stuks

Een nederlandstalige website bouwen met rails is als rijden in een stoptrein. Scaffolding gebruikt; de volgende halte is “het aanpassen van de knoppen en labels”, validaties toegevoegd; de volgende halte is “het vertalen van de foutmeldingen” etc. etc. Alle snelheids verhogende features zijn doordrenkt van engelse drempels. Ik wil met de intercity!

Met de dutchify plugin doe ik een poging om alle amerikanismes aan de presentatie kant aan te pakken. Ik heb me bewust alleen op nederlands gericht omdat ik me niet alle i18n en l10n problemen op de hals wil halen, deze zijn veel te gemakkelijk te onderschatten. Ook hou ik me verre van het vertalen van classes en methodes, voor je het weet zit je een source-filter te schrijven als perligata.

Het gebruiken van een nederlandstalig datamodel valt buiten deze plugin. Hier valt veel voor te zeggen en is vaak zelfs belangrijk voor het beheersbaar houden van een project.

Lees verder →