ruby: url_to_constant 1

A small bit of ruby to get a constant from an URL: [ruby] require 'uri' def url_to_constant(url) return URI.parse(url).host.gsub(/^www\./, '').capitalize.gsub(/[^a-z][a-z]/i) { |m| m.gsub(/[^a-z]/, '').upcase }.constantize end Nothing exceptionnal here, just a pretext to post something....

yaml, activerecord and acts_as_nested_set

I used to use this yaml_to_ar lib from christophe to load categories tree into my database, using acts_as_tree in the model that was perfect. Arrived the time when I felt the need to use acts_as_nested_set instead, for which I had to fill the lft and rgt columns. So I just rewrote the yaml_to_ar...

my first rails plugin: named_resources 6

It's a simple plugin (2 lines of code beside class and modules declarations) which allows routes created via the map.resources mechanism to be customized. Say you have the following map: [ruby] map.resources :members It will generate routes like: /members /members/:id /members/new No say you want...

Top tags