Rails CRUD Actions Plugin 3
For a while now I’ve been using a plugin I wrote that provides simple and versatile CRUD actions to Rails controllers.
About six months ago I was getting really fed up with writing the same actions over and over again: new, create, show, edit, update, list, destroy. So, I decided to abstract them out into a plugin.
All I have to do to get almost all the CRUD goodness I need is:class NodeController < ApplicationController
include CrudActions
endNow the NodeController has new, create, show, edit, update, list, and destroy actions for the Node ActiveRecord Model. Likewise if CrudActions were included in ArticleController , ArticleController would have actions for the Article Model.
All of the actions work as you’d expect and assign variables for your views appropriately (@node, @nodes, @paginator, etc.).
For customization you can easily wrap the actions provided like so:class NodeController < ApplicationController
include CrudActions
alias_method :original_list, :list
def list
Node.with_scope(:find => { :conditions => 'id != 1' } ) do
original_list
end
end
endThe source is hosted at Google Code: http://code.google.com/p/rails-crud-actions.
The meat of the plugin is in crud_actions.rb.
There is still plenty of room for this concept to grow, implementing respond_to for example. However, I’m not sure that I’m going down a wise path here. Everything about this approach feels shaky… but it is so damned convenient.
Please have a look. I’d really like some feedback.