The joy of 'rolling your own' with Camping.

by Gregory Brown

Beauty is in the eye of the beholder



In my experience, there are a few different attitudes when it comes to beautiful design. Many consider Rails to be a beautiful framework to work with. In it's own right, I certainly would agree with these folks. If you're willing to accept the 80/20 divide and the tool fits the job, it could be dreamy to work with Rails. But in my limited experience, I sort of feel like a decision to work with Rails is more or less an all-or-nothing decision.

Like a train that wants to go east but only has tracks running North to South, a change in course is going to create some major problems. I don't think this is a bad design, that's what a train is meant to do. But maybe for some jobs, you need a dune buggy. That's where the little wheels come in.

The camping framework is designed in light of another definition of beauty, and that definition is closer to the austere. When I started a job in it, I asked the usual questions one might run into when dealing with a small web app. "Does camping support sessions|file uploads|static files"

The answers were, 'sort of','nope','nope'. But all three were also appended with a "but it's easy to roll your own". The rest of this article will show you one way to do all three, and hopefully show some appreciation for the simplicity of the task.

12 Comments

evan
2007-01-04 13:08:58
Hi, Greg. The static files example had gone a bit out of date; I updated it on the wiki. You may want to reflect the new changes here to avoid confusion.


Thanks for this! How to handle file uploads is a very common question. Note that unlike in Rails, the tempfile method works for any size file, no matter how small.

Greg
2007-01-04 13:41:47
evan,


Done! Thanks for the feedback!

Christoffer Sawicki
2007-01-04 18:32:56
I think Merb (http://merb.rubyforge.org/) deserves a mention in this context. There.
Greg
2007-01-04 19:15:21
Chritstoffer,


I actually thought about mentioning Merb, because I think it's super cool. But I wasn't sure how to mention it in this article, and also haven't really dug into it yet. :)

Greg
2007-01-04 19:36:29
Christoffer,


Sorry for butchering your name above.

_why
2007-01-05 17:10:40
Thanks for writing this! You make it sound so adventurous.


You can use redirect Import rather than redirect "import", if your controller is constant Import.

Greg
2007-01-05 17:21:40
_why,


Ah, but you sir are the one who made it an adventure!


Thanks for the tip, I'll update the article.

Greg
2007-01-16 17:10:03
I was having trouble with Pathname on win2k, so i've updated the example..

2007-04-12 13:17:16
path[/.w+$/, 0] should be path[/\.\w+$/, 0]
Gregory
2007-04-12 19:15:09
good catch, will update!
Gregory
2007-04-12 19:28:15
Annoying! the blog is eating my formatting. i'll need to look it later.. sorry
anonymous coward
2008-07-26 16:18:05
These days it's:
file = @input.File[:tempfile].read