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



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

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



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

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

#editObject



58
59
60
# File 'app/controllers/cambium/admin_controller.rb', line 58

def edit
  set_object
end

#indexObject



12
13
14
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/cambium/admin_controller.rb', line 12

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



43
44
45
# File 'app/controllers/cambium/admin_controller.rb', line 43

def new
  @object = admin_model.new
end

#showObject



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

def show
  set_object
  redirect_to(admin_routes.edit)
end

#updateObject



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

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