Created
June 11, 2011 14:41
-
-
Save marcelloma/1020614 to your computer and use it in GitHub Desktop.
Crud For Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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