Dynamic Restful Scaffolding
It seems this interest in restful rails apps is bringing out a number of restful scaffolding frameworks too. Once you make a few resource controllers, they all start looking the same. The main differences usually lie in the model scoping and authentication filters. It's natural to look at this and try to devise some DRY way to define these actions. Jeremy is not the first to attempt this, with his experimental "Rapid Resource":http://www.jvoorhis.org/articles/2006/08/04/prototyping-with-rapid-resource-a-proof-of-concept macros. I took a stab too: "http://pastie.caboo.se/7319":http://pastie.caboo.se/7319.
This approach seemed to work well in my basic tests. However, it became apparent that I would have to allow for customizations on nearly every line of code. Take this standard create action and note the areas you may want to configure:
def create
@post = Post.new(params[:post])
@post.save!
redirect_to post_path(@post)
rescue ActiveRecord::RecordInvalid
render :action => 'new'
end
- Does Post have a parent model? Maybe you want @user.posts.build(params[:post]) ?
- Do you want to redirect somewhere else?
- Do you want to Flash notices?
- Do you want to respond to alternate content types such as XML, YAML, Atom?
The dynamic scaffolding code could get pretty complicated with all these customizations. The application developer now has to remember various new methods to overwrite to customize various aspects of the app. None of this feels right, especially when the initial controller code is so basic. Maybe instead of working on this, I'll focus on the app and let these similar controllers evolve naturally. However, I do have a very basic "resource generator":http://svn.techno-weenie.net/projects/plugins/resource_generator/ that I threw together.
related
- 2010 Aug 03 Protocol Buffers with Riak for Node.js
- 2010 Jul 13 In-Process Node.js Queues
- 2010 Jul 07 Geek Talk Interview
- 2010 Jun 28 Tee and Child Processes
- 2010 Jun 23 You can let go now
- 2010 May 17 Railsconf: Building APIs
- 2010 May 10 Nori: Node.js Riak wrapper
- 2010 May 10 No, I did not create a mobile phone framework too
- 2010 May 04 Escaping your test suite with your life
- 2010 Apr 05 Will the iPad kill comic books?

