Class: ModelInfo::ModelsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/model_info/models_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
# File 'app/controllers/model_info/models_controller.rb', line 18

def create
  @model_data = @model_class.new(permit_params)
  if @model_data.save
    redirect_to model_show_path(model_class: @model_class, model_object_id: @model_data.id)
  else
    flash[:error] = @model_data.errors.full_messages
    redirect_back(fallback_location: request.referrer)
  end
end

#destroyObject



41
42
43
44
# File 'app/controllers/model_info/models_controller.rb', line 41

def destroy
  @model_class.find(params[:model_object_id]).destroy
  redirect_back(fallback_location: request.referrer)
end

#editObject



28
# File 'app/controllers/model_info/models_controller.rb', line 28

def edit; end

#indexObject



8
9
10
11
12
# File 'app/controllers/model_info/models_controller.rb', line 8

def index
  @model_class = params[:model_class] || @model_array&.first
  @page = params[:page] || 1
  @model_pagination = @model_class.constantize.page(@page).per(10)
end

#newObject



14
15
16
# File 'app/controllers/model_info/models_controller.rb', line 14

def new
  @model_data = @model_class.new
end

#showObject



30
# File 'app/controllers/model_info/models_controller.rb', line 30

def show; end

#updateObject



32
33
34
35
36
37
38
39
# File 'app/controllers/model_info/models_controller.rb', line 32

def update
  if @model_data.update(permit_params)
    redirect_to model_show_path(model_class: @model_class, model_object_id: @model_data.id)
  else
    flash[:error] = @model_data.errors.full_messages
    redirect_back(fallback_location: request.referrer)
  end
end