Skip to content

Instantly share code, notes, and snippets.

@marcelloma
Created June 11, 2011 14:41
Show Gist options
  • Save marcelloma/1020614 to your computer and use it in GitHub Desktop.
Save marcelloma/1020614 to your computer and use it in GitHub Desktop.
Crud For Plugin
module CrudFor
def crud_for(model)
expose(model.to_sym)
expose(model.to_s.pluralize.to_sym) { search.paginate(:page => params[:page]) }
expose(:search) { model.to_s.capitalize.constantize.search(params[:search]) }
self.class_eval %"
def create
if #{model}.save
redirect_to #{model.to_s.pluralize}_url
else
render 'new'
end
end
def update
#{model}.update_attributes(params['#{model.to_sym}'])
redirect_to #{model.to_s.pluralize}_url
end
def destroy
#{model}.destroy
redirect_to #{model.to_s.pluralize}_url
end
"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment