Plugins to Help your Rails Controllers REST Easy

Update 2007-11-02: Fixed reference to Mephisto author. Thanks Luigi!

Update 2007-11-01: Nathan commented on this post and said m_r will soon support polymorphic routes.


One of the nice features in Ruby on Rails is its support for REST-style controllers. This feature is fledgling in Rails 1.2.3, so if you head down this path you will doubtless find yourself writing a lot of similar-yet-faintly-different code again and again. A number of generous people have written plugins to ease the pain. I did a test run with two lately — make_resourceful and resource_controller — and investigated several others along the way. This is a summary of what I found.

make_resourceful comes from Hampton Catlin (Toronto), Jeff Hardy, and Nathan Weizenbaum, the same crew that does the very cool HAML and SASS plugins. m_r has a pretty syntax, great documentation, and a fairly active google group where Hampton and Nathan engage in discussions. I took it for a test run and quite liked how my code ended up after transmogrification. On the down side, I needed a feature called “polymorphic routes” — e.g. \people\bob\posts or \forums\13\posts — which this plugin doesn’t have built in, but Jonathan Linowes has patched. Alas, I found the combination of the patch and plugin unwieldy: it took me way too long to get it all working for my specific requirements, and the resulting code was, shall we say, Frankensteinesque.

resource_controller is written by Montrealler James Golick, who is buddies with the make_resourceful  team members. James’ plugin is quite similar to m_r — the syntax is much the same — and happily for me has built-in support for polymorphic routes. I tried it out and liked the basics, but then found myself stymied by difficulty supporting some custom route formats. I asked James for help, and he was incredibly responsive; he resurfaced just one day later with a new revision that let me customize to my heart’s content. He also made some design changes so that r_c can be instantiated either using inheritance (the original design: your app controller inherits from ResourceController::Base) or as a mixin. These changes are now available in revision 83 of his SVN trunk.  James also fired up a google group just recently and takes questions on his blog. 

I also looked at:

  • resources_controller – from Ian White, who has written several other plugins.  (Yes, this plugin has almost the same name as James Golick’s resource_controller. Ian was first.) His plugin looks very functional but I avoided it because I found the syntax unappealing.
  • restful_exposure - Luke Redpath. This one didn’t meet my requirements.
  • define_crud - SonicIQ. No docs = no soup for you.

Bottom line: I recommend you check out both resource_controller and make_resourceful.  I am going with resource_controller for now, since it meets all my requirements and James clearly has a ton of energy around improving it further in the directions I care about. make_resourceful also impressed me a great deal, so if you don’t need polymorphic routes it might be a better solution for you.

FolderShare is Good… Except for the Ghosts

FolderShare has done a bang-up job for a few years synchronizing my files amongst several computers. Recently I used it to collaborate with relatives to collect photos for my brother-in-law’s wedding. At home it does a lot of heavy lifting every day to synch (and, effectively, back up) work files, music and pictures between Katrin and myself. It does have a few pesky limitations, like a 10,000 file per folder limit in the basic version, but you can work around those fairly easily. 

Today, though, I ran into an interesting hurdle: Foldershare has a ‘trash’ directory where it stuffs little ghost copies of every file you delete from a foldershare’d directory. This is a feature: you can always retrieve a deleted file if you want to. But it has a down side, too: so far, nobody has invented an infinitely large disk drive.

This morning, my 60GB C: drive, which has been hovering at fairly low disk space for the past few months, finally hit rock bottom. Windows Media complaining that it had no library space, Firefox crashing during security updates, dogs and cats living together – mass hysteria.  So I hauled out my super-disk-space-radar-gun — SpaceMonger — to find out who was hogging all the space. The nefarious culprit: FolderShare’s trash folder, clocking in at a massive 5.3 GB.

Yikes.

Gulp.

DELETE!

Hopefully Microsoft will release an update some time and add a feature to automatically limit the trash folder size.

I still heartily recommend FolderShare as a great solution for continuous file synch, but do keep this devilish little flaw in mind.

 

If you must know more:

2007 Ontario Election Roundup

Ontario’s 2007 election and referendum results are mostly in, with 98% of polls reporting. In a nutshell:

  • Little changed in terms of seats allocated to political parties
  • The MMP proposal got approval from 37% of voters; 60% was needed to pass
  • The Green party won zero seats, but received 8.2% of the popular vote
  • Voter turnout was a record low, under 50%

The table below shows the results, and what they would have been, were the MMP system in place.

If you do the math you’ll see that MMP approval — 37% of the popular vote — exceeds the total percentage of Green Party and NDP votes (8.2% + 16.8%) by a further 12%. That means a lot of people who voted for the PC or Liberal party also voted in favor of MMP. This despite the confusion, uncertainty and doubt reported by the major media.

The huge gain by the Green party is also significant: it indicates far more environmental concern now than in ’03 when the Green Party received only 3% of the popular vote. We should expect (and demand) that mainstream party agendas become more green in the years ahead.

Party

Percentage of popular vote

Seats under current system

Riding seats under MMP

Total seats under MMP

Liberals

42%

71

60

60

Progressive Conservatives

31.7%

25

21

39

NDP

16.8%

11

9

20

Green Party

8.2%

0

0

10

(Source: Globe and Mail)

I’m hoping for better preparation next time around. Flavors of proportional representation are used successfully today in New Zealand, Venezuela, Hungary, Scotland’s parliament, Wales’ national assembly, and every European country except Britain. We can do at least as well as them, and certainly better than First Past the Post.

Follow

Get every new post delivered to your Inbox.

Join 401 other followers

%d bloggers like this: