Class: Carload::DashboardController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper, Croppable
Defined in:
app/controllers/carload/dashboard_controller.rb

Instance Method Summary collapse

Methods included from ApplicationHelper

#associated_model_name, #id_or_ids, #image?, #needs_upload?, #polymorphic?

Instance Method Details

#createObject



42
43
44
45
46
47
48
49
50
# File 'app/controllers/carload/dashboard_controller.rb', line 42

def create
  authorize :carload_dashboard, :create? unless Carload.auth_solution == :none
  @object = @model_class.create model_params
  if @object.save
    redirect_to action: :index, model: @model_names # TODO: To show page.
  else
    render :new
  end
end

#destroyObject



61
62
63
64
65
# File 'app/controllers/carload/dashboard_controller.rb', line 61

def destroy
  authorize :carload_dashboard, :destroy? unless Carload.auth_solution == :none
  @object.destroy
  redirect_to action: :index, model: @model_names
end

#editObject



38
39
40
# File 'app/controllers/carload/dashboard_controller.rb', line 38

def edit
  authorize :carload_dashboard, :edit? unless Carload.auth_solution == :none
end

#indexObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/carload/dashboard_controller.rb', line 16

def index
  authorize :carload_dashboard, :index? unless Carload.auth_solution == :none
  if params[:search].present?
    @query = params[:search][:query]
    case Carload.search_engine
    when :elasticsearch
      @objects = @model_class.search(params[:search][:query]).records.page(params[:page])
    when :pg_search
      @objects = @model_class.search(params[:search][:query]).page(params[:page])
    end
  else
    @objects = @model_class.page(params[:page])
  end
  @show_attributes = Dashboard.model(@model_name).index_page[:shows][:attributes] + [:created_at, :updated_at]
  render "dashboard/#{@model_names}/index.html.erb"
end

#newObject



33
34
35
36
# File 'app/controllers/carload/dashboard_controller.rb', line 33

def new
  authorize :carload_dashboard, :new? unless Carload.auth_solution == :none
  @object = @model_class.new
end

#searchObject



67
68
69
70
# File 'app/controllers/carload/dashboard_controller.rb', line 67

def search
  params[:action] = :index # To make rescue_missing_template use correct index action.
  index
end

#show_configObject



72
73
# File 'app/controllers/carload/dashboard_controller.rb', line 72

def show_config
end

#updateObject



52
53
54
55
56
57
58
59
# File 'app/controllers/carload/dashboard_controller.rb', line 52

def update
  authorize :carload_dashboard, :update? unless Carload.auth_solution == :none
  if @object.update model_params
    redirect_to action: :index, model: @model_names # TODO: To show page.
  else
    render :edit
  end
end