Class: AdminData::CrudController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin_data/crud_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#klass

Instance Method Summary collapse

Instance Method Details

#createObject



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.full_messages.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

#delObject



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

#destroyObject



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

#editObject



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

#newObject



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

#showObject



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

#updateObject



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.full_messages.join } }
    end
  end
end