Class: MerbAdmin::Main
Instance Method Summary
collapse
#object_label, #object_property, #paginate, #to_model_name
#app_path_for, #image_path, #javascript_path, #public_path_for, #slice_path_for, #stylesheet_path
Instance Method Details
#create ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'app/controllers/main.rb', line 43
def create
@object = @abstract_model.new(@attributes)
if @object.save && update_all_associations
redirect_on_success
else
render_error(:new)
end
end
|
#delete ⇒ Object
64
65
66
|
# File 'app/controllers/main.rb', line 64
def delete
render(:layout => 'form')
end
|
#destroy ⇒ Object
68
69
70
71
72
73
74
|
# File 'app/controllers/main.rb', line 68
def destroy
if @object.destroy
redirect(url(:merb_admin_list, :model_name => @abstract_model.to_param), :message => {:notice => "#{@abstract_model.pretty_name} was successfully destroyed"})
else
raise BadRequest
end
end
|
#edit ⇒ Object
52
53
54
|
# File 'app/controllers/main.rb', line 52
def edit
render(:layout => 'form')
end
|
#index ⇒ Object
10
11
12
13
|
# File 'app/controllers/main.rb', line 10
def index
@abstract_models = MerbAdmin::AbstractModel.all
render(:layout => 'dashboard')
end
|
#list ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/main.rb', line 15
def list
options = {}
options.merge!(get_sort_hash)
options.merge!(get_sort_reverse_hash)
options.merge!(get_query_hash(options))
options.merge!(get_filter_hash(options))
per_page = MerbAdmin[:per_page]
if params[:all]
options.merge!(:limit => per_page * 2)
@objects = @abstract_model.all(options).reverse
else
@current_page = (params[:page] || 1).to_i
options.merge!(:page => @current_page, :per_page => per_page)
@page_count, @objects = @abstract_model.paginated(options)
options.delete(:page)
options.delete(:per_page)
options.delete(:offset)
options.delete(:limit)
end
@record_count = @abstract_model.count(options)
render(:layout => 'list')
end
|
#new ⇒ Object
38
39
40
41
|
# File 'app/controllers/main.rb', line 38
def new
@object = @abstract_model.new
render(:layout => 'form')
end
|
#update ⇒ Object
56
57
58
59
60
61
62
|
# File 'app/controllers/main.rb', line 56
def update
if @object.update_attributes(@attributes) && update_all_associations
redirect_on_success
else
render_error(:edit)
end
end
|