Class: Cambium::AdminController

Inherits:
BaseController
  • Object
show all
Includes:
CambiumHelper
Defined in:
app/controllers/cambium/admin_controller.rb

Instance Method Summary collapse

Methods included from CambiumHelper

#admin, #admin_form, #admin_model, #admin_routes, #admin_table, #admin_view, #avatar, #cambium_field, #cambium_form, #cambium_form_fields, #cambium_page_title, #cambium_route, #cambium_table, #can_delete?, #has_new_form?, #is_edit?, #is_index?, #not_found

Instance Method Details

#createObject



45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/cambium/admin_controller.rb', line 45

def create
  @object = admin_model.new(create_params)
  if @object.save
    redirect_to(
      admin_routes.index,
      :notice => "#{admin_model.to_s.gsub(/Cambium::/, '')} created!")
  else
    render 'new'
  end
end

#destroyObject



71
72
73
74
75
76
77
# File 'app/controllers/cambium/admin_controller.rb', line 71

def destroy
  set_object
  @object.destroy
  redirect_to(
    admin_routes.index,
    :notice => "#{admin_model.to_s.gsub(/Cambium::/, '')} deleted!")
end

#editObject



56
57
58
# File 'app/controllers/cambium/admin_controller.rb', line 56

def edit
  set_object
end

#indexObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/cambium/admin_controller.rb', line 10

def index
  respond_to do |format|
    scope = admin_table.scope
    if params[:sort_by]
      @collection = admin_model.unscoped
        .order("#{params[:sort_by]} #{params[:order] || 'asc'}")
    else
      if scope.split('.').size > 1
        @collection = admin_model
        scope.split('.').each do |s|
          @collection = @collection.send(s)
        end
      else
        @collection = admin_model.send(admin_table.scope)
      end
    end
    format.html do
      @collection = @collection.page(params[:page] || 1).per(15)
      render :layout => false if params[:no_layout]
    end
    format.csv do
      send_data admin.to_csv(@collection)
    end
  end
end

#newObject



41
42
43
# File 'app/controllers/cambium/admin_controller.rb', line 41

def new
  @object = admin_model.new
end

#showObject



36
37
38
39
# File 'app/controllers/cambium/admin_controller.rb', line 36

def show
  set_object
  redirect_to(admin_routes.edit)
end

#updateObject



60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/cambium/admin_controller.rb', line 60

def update
  set_object
  if @object.update(update_params)
    redirect_to(
      admin_routes.index,
      :notice => "#{admin_model.to_s.gsub(/Cambium::/, '')} updated!")
  else
    render 'edit'
  end
end