Class: MerbAdmin::Main

Inherits:
Application show all
Includes:
Merb::MerbAdmin::MainHelper
Defined in:
app/controllers/main.rb

Instance Method Summary collapse

Methods included from Merb::MerbAdmin::MainHelper

#object_label, #object_property, #paginate, #to_model_name

Methods included from Merb::MerbAdmin::ApplicationHelper

#app_path_for, #image_path, #javascript_path, #public_path_for, #slice_path_for, #stylesheet_path

Instance Method Details

#createObject



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

#deleteObject



64
65
66
# File 'app/controllers/main.rb', line 64

def delete
  render(:layout => 'form')
end

#destroyObject



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

#editObject



52
53
54
# File 'app/controllers/main.rb', line 52

def edit
  render(:layout => 'form')
end

#indexObject



10
11
12
13
# File 'app/controllers/main.rb', line 10

def index
  @abstract_models = MerbAdmin::AbstractModel.all
  render(:layout => 'dashboard')
end

#listObject



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

#newObject



38
39
40
41
# File 'app/controllers/main.rb', line 38

def new
  @object = @abstract_model.new
  render(:layout => 'form')
end

#updateObject



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