Class: BaseController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/base_controller.rb

Constant Summary collapse

PER_PAGE =
6

Instance Method Summary collapse

Instance Method Details

#createObject



32
33
34
35
36
# File 'app/controllers/base_controller.rb', line 32

def create
  instance_variable_set(instance_variable, model.new(permit_params))
  flash[:success] = I18n.t('created', model: model.model_name.human) if variable.save
  responds
end

#destroyObject



43
44
45
46
# File 'app/controllers/base_controller.rb', line 43

def destroy
  flash[:success] = I18n.t('destroyed', model: model.model_name.human) if variable.destroy
  redirect_to index_path
end

#editObject



29
30
# File 'app/controllers/base_controller.rb', line 29

def edit
end

#indexObject



12
13
14
15
16
17
18
19
20
# File 'app/controllers/base_controller.rb', line 12

def index
  if included_attributes
    instance_variable_set(collection_instance_variable, model.includes(included_attributes).paginate(page: params[:page], per_page: PER_PAGE))
  else
    instance_variable_set(collection_instance_variable, model.paginate(page: params[:page], per_page: PER_PAGE))
  end
  search
  respond_with collection_variable
end

#newObject



25
26
27
# File 'app/controllers/base_controller.rb', line 25

def new
  instance_variable_set(instance_variable, model.new)
end

#showObject



22
23
# File 'app/controllers/base_controller.rb', line 22

def show
end

#template_not_foundObject



48
49
50
# File 'app/controllers/base_controller.rb', line 48

def template_not_found
  redirect_to '/404.html'
end

#updateObject



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

def update
  flash[:success] = I18n.t('updated', model: model.model_name.human) if variable.update(permit_params)
  responds
end