[rspec-users] spec'ing metaprograming & rails CRUD
Michael Trier
mtrier at eminentconsultinggroup.com
Sat Mar 24 09:32:06 EDT 2007
On Mar 24, 2007, at 5:11 AM, Scott Taylor wrote:
>
> For edge rails there is a Crud generator. There is also a CRUD
> controller that is out there from which you can inherit your other
> controllers (see http://geekonomics.blogspot.com/2006/07/crud-and-
> shared-controllers.html)
>
> This got me thinking about Crud controllers in general. As far as I
> know, the generator can't produce crud classes which are nested
> (i.e. /posts/1/comments/7). So I thought about creating my own Crud
> class from which to inherit from, with some private methods, like so:
>
> class CrudController < ActiveRecord::Base
> class << self
> private
> def model
> # get a default name based on the controller name
> # or specify a name
> end
>
> def belongs_to
> # the model's "belongs_to"/foreign key relationship
> # this could also be found dynamically
> end
> end
> end
>
> class CommentsController < CrudController
> model :comments
> belongs_to :post
> end
You might want to look into the resource_controller plugin: (http://
svn.ardes.com/rails_plugins/resources_controller/
It does what you're describing in a very nice way and supports nested
as well as acts_as_tree situations.
Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070324/47027130/attachment-0001.html
More information about the rspec-users
mailing list