Class: Admin::LookupsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/lookups_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#policy

Methods included from SortableColumns

#sortable_columns

Methods included from ResourceHelpers

#add_success_msg, #apply, #build_resource, #load_resource!, #per_page, #redirect_after_save, #redirect_or_render, #resource, #resource_model, #resource_name, #resource_params, #resources

Methods included from PathHistory

#back_uri, #last_uri, #no_cache!, #redirect_to_back, #redirect_to_last, #store_path_history

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
# File 'app/controllers/admin/lookups_controller.rb', line 18

def create
  @lookup = Lookup.new(params[:lookup])
  if @lookup.save
    redirect_to admin_lookups_index_path(category: @lookup.category)
  else
    render :new
  end
end

#destroyObject



44
45
46
47
48
# File 'app/controllers/admin/lookups_controller.rb', line 44

def destroy
  @lookup = Lookup.find(params[:id])
  @lookup.destroy
  redirect_to admin_lookups_index_path(category: @lookup.category)
end

#editObject



31
32
33
# File 'app/controllers/admin/lookups_controller.rb', line 31

def edit
  @lookup = Lookup.find(params[:id])
end

#indexObject



5
6
7
8
9
10
11
12
# File 'app/controllers/admin/lookups_controller.rb', line 5

def index
  @category = params[:category]
  @lookups = Lookup.where(category: @category).order(:code, :created_at)
  if @lookups.blank? && @category.present?
    redirect_to admin_lookups_index_path
    return
  end
end

#newObject



14
15
16
# File 'app/controllers/admin/lookups_controller.rb', line 14

def new
  @lookup = Lookup.new
end

#showObject



27
28
29
# File 'app/controllers/admin/lookups_controller.rb', line 27

def show
  @lookup = Lookup.find(params[:id])
end

#updateObject



35
36
37
38
39
40
41
42
# File 'app/controllers/admin/lookups_controller.rb', line 35

def update
  @lookup = Lookup.find(params[:id])
  if @lookup.update_attributes(params[:lookup].permit!)
    redirect_to admin_lookups_index_path(category: @lookup.category)
  else
    render :edit
  end
end