Class: AdminData::CrudController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- AdminData::CrudController
- Defined in:
- app/controllers/admin_data/crud_controller.rb
Instance Attribute Summary
Attributes inherited from ApplicationController
Instance Method Summary collapse
- #create ⇒ Object
- #del ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/admin_data/crud_controller.rb', line 58 def create model_attrs = params[@klass.name.underscore] @model = @klass.create(model_attrs) @columns = columns_list respond_to do |format| if @model.errors.any? format.html { render :action => 'new' } format.js { render :json => {:error => @model.errors..join() }} else format.html do flash[:success] = "Record was created" redirect_to admin_data_path(:id => @model.id, :klass => @klass.name.underscore) end format.js { render :json => {} } end end end |
#del ⇒ Object
21 22 23 24 25 |
# File 'app/controllers/admin_data/crud_controller.rb', line 21 def del @klass.send(:delete, params[:id]) flash[:success] = 'Record was deleted' redirect_to admin_data_search_path(:klass => @klass.name.underscore) end |
#destroy ⇒ Object
16 17 18 19 |
# File 'app/controllers/admin_data/crud_controller.rb', line 16 def destroy @klass.send(:destroy, params[:id]) redirect_to admin_data_search_path(:klass => @klass.name.underscore) end |
#edit ⇒ Object
27 28 29 30 31 |
# File 'app/controllers/admin_data/crud_controller.rb', line 27 def edit @page_title = "edit #{@klass.name.underscore}:#{@model.id}" @columns = columns_list respond_to {|format| format.html} end |
#new ⇒ Object
33 34 35 36 37 38 |
# File 'app/controllers/admin_data/crud_controller.rb', line 33 def new @page_title = "new #{@klass.name.underscore}" @model = @klass.send(:new) @columns = columns_list respond_to {|format| format.html} end |
#show ⇒ Object
11 12 13 14 |
# File 'app/controllers/admin_data/crud_controller.rb', line 11 def show @page_title = "#{@klass.name.underscore}:#{@model.id}" respond_to {|format| format.html} end |
#update ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/admin_data/crud_controller.rb', line 40 def update model_attrs = params[@klass.name.underscore] @columns = columns_list respond_to do |format| if @model.update_attributes(model_attrs) format.html do flash[:success] = "Record was updated" redirect_to admin_data_path(:id => @model.id, :klass => @klass.name.underscore) end format.js { render :json => {:success => true}} else format.html { render :action => 'edit' } format.js { render :json => {:error => @model.errors..join } } end end end |