Class: Administrate::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/administrate/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/administrate/application_controller.rb', line 42

def create
  resource = new_resource(resource_params)
  authorize_resource(resource)

  if resource.save
    yield(resource) if block_given?
    redirect_to(
      after_resource_created_path(resource),
      notice: translate_with_resource("create.success")
    )
  else
    render :new, locals: {
      page: Administrate::Page::Form.new(dashboard, resource)
    }, status: :unprocessable_entity
  end
end

#destroyObject



73
74
75
76
77
78
79
80
# File 'app/controllers/administrate/application_controller.rb', line 73

def destroy
  if requested_resource.destroy
    flash[:notice] = translate_with_resource("destroy.success")
  else
    flash[:error] = requested_resource.errors.full_messages.join("<br/>")
  end
  redirect_to after_resource_destroyed_path(requested_resource), status: :see_other
end

#editObject



36
37
38
39
40
# File 'app/controllers/administrate/application_controller.rb', line 36

def edit
  render locals: {
    page: Administrate::Page::Form.new(dashboard, requested_resource)
  }
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/administrate/application_controller.rb', line 5

def index
  authorize_resource(resource_class)
  search_term = params[:search].to_s.strip
  resources = filter_resources(scoped_resource, search_term: search_term)
  resources = apply_collection_includes(resources)
  resources = order.apply(resources)
  resources = paginate_resources(resources)
  page = Administrate::Page::Collection.new(dashboard, order: order)

  render locals: {
    resources: resources,
    search_term: search_term,
    page: page,
    show_search_bar: show_search_bar?
  }
end

#newObject



28
29
30
31
32
33
34
# File 'app/controllers/administrate/application_controller.rb', line 28

def new
  resource = new_resource
  authorize_resource(resource)
  render locals: {
    page: Administrate::Page::Form.new(dashboard, resource)
  }
end

#showObject



22
23
24
25
26
# File 'app/controllers/administrate/application_controller.rb', line 22

def show
  render locals: {
    page: Administrate::Page::Show.new(dashboard, requested_resource)
  }
end

#updateObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/administrate/application_controller.rb', line 59

def update
  if requested_resource.update(resource_params)
    redirect_to(
      after_resource_updated_path(requested_resource),
      notice: translate_with_resource("update.success"),
      status: :see_other
    )
  else
    render :edit, locals: {
      page: Administrate::Page::Form.new(dashboard, requested_resource)
    }, status: :unprocessable_entity
  end
end