Class: ModelInfo::AssociationsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
# File 'app/controllers/model_info/associations_controller.rb', line 23

def create
  @associated_model_data = @model_data.send(@associated_model_name).build(permit_params)
  if @associated_model_data.save
    redirect_to association_show_path(associated_model_object_id: @associated_model_data.id)
  else
    flash[:error] = @associated_model_data.errors.full_messages
    redirect_back(fallback_location: request.referrer)
  end
end

#destroyObject



48
49
50
51
# File 'app/controllers/model_info/associations_controller.rb', line 48

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

#editObject



36
37
# File 'app/controllers/model_info/associations_controller.rb', line 36

def edit
end

#indexObject



13
14
15
16
17
18
19
20
21
# File 'app/controllers/model_info/associations_controller.rb', line 13

def index
  @macro, @page = params[:macro], params[:page]
  @associated_model_data = @model_data.send(@associated_model_name)
  if @macro == 'has_one' || @macro == 'belongs_to'
    @associated_model_pagination = 1
  else
    @associated_model_pagination = @associated_model_data.page(params[:page]).per(10)
  end
end

#newObject



9
10
11
# File 'app/controllers/model_info/associations_controller.rb', line 9

def new
  @associated_model_data = @model_data.send(@associated_model_name).build
end

#showObject



33
34
# File 'app/controllers/model_info/associations_controller.rb', line 33

def show
end

#updateObject



39
40
41
42
43
44
45
46
# File 'app/controllers/model_info/associations_controller.rb', line 39

def update
  if @associated_model_data.update(permit_params)
    redirect_to association_show_path(associated_model_object_id: params[:associated_model_object_id])
  else
    flash[:error] = @associated_model_data.errors.full_messages
    redirect_back(fallback_location: request.referrer)
  end
end