Class: AdminData::MainController
Instance Attribute Summary
#klass, #model
Instance Method Summary
collapse
Methods included from Chelper
#admin_data_invalid_record_link, #admin_data_is_allowed_to_update?, #admin_data_is_allowed_to_update_model?, #admin_data_is_allowed_to_view?, #admin_data_is_allowed_to_view_klass?, #per_page
Instance Method Details
#all_models ⇒ Object
35
36
37
|
# File 'app/controllers/admin_data/main_controller.rb', line 35
def all_models
respond_to {|format| format.html}
end
|
#create ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'app/controllers/admin_data/main_controller.rb', line 86
def create
model_name_underscored = @klass.name.underscore
model_attrs = params[model_name_underscored]
@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_on_k_path(:id => @model, :klass => @klass.name.underscore)
end
format.js { render :json => {} }
end
end
end
|
#del ⇒ Object
49
50
51
52
53
|
# File 'app/controllers/admin_data/main_controller.rb', line 49
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
44
45
46
47
|
# File 'app/controllers/admin_data/main_controller.rb', line 44
def destroy
@klass.send(:destroy, params[:id])
redirect_to admin_data_search_path(:klass => @klass.name.underscore)
end
|
#edit ⇒ Object
55
56
57
58
59
|
# File 'app/controllers/admin_data/main_controller.rb', line 55
def edit
@page_title = "edit #{@klass.name.underscore}:#{@model.id}"
@columns = columns_list
respond_to {|format| format.html}
end
|
#new ⇒ Object
61
62
63
64
65
66
|
# File 'app/controllers/admin_data/main_controller.rb', line 61
def new
@page_title = "new #{@klass.name.underscore}"
@model = @klass.send(:new)
@columns = columns_list
respond_to {|format| format.html}
end
|
#show ⇒ Object
39
40
41
42
|
# File 'app/controllers/admin_data/main_controller.rb', line 39
def show
@page_title = "#{@klass.name.underscore}:#{@model.id}"
respond_to {|format| format.html}
end
|
#table_structure ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/controllers/admin_data/main_controller.rb', line 18
def table_structure
@page_title = 'table_structure'
@indexes = []
if (indexes = ActiveRecord::Base.connection.indexes(@klass.table_name)).any?
add_index_statements = indexes.map do |index|
statment_parts = [ ('add_index ' + index.table.inspect) ]
statment_parts << index.columns.inspect
statment_parts << (':name => ' + index.name.inspect)
statment_parts << ':unique => true' if index.unique
' ' + statment_parts.join(', ')
end
add_index_statements.sort.each { |index| @indexes << index }
end
respond_to {|format| format.html}
end
|
#update ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'app/controllers/admin_data/main_controller.rb', line 68
def update
model_name_underscored = @klass.name.underscore
model_attrs = params[model_name_underscored]
@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_on_k_path(:id => @model, :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
|