Class: Infold::AttachmentFieldsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/infold/attachment_fields_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/infold/attachment_fields_controller.rb', line 13

def create
  @model = Model.find(params[:model_id])
  @attachment_field = @model.attachment_fields.build
  @attachment_field.assign_attributes(post_params)
  if @attachment_field.save
    redirect_to model_attachment_fields_path, flash: { info: t('infold.flash.created') }
  else
    flash.now[:warning] = t('infold.flash.invalid')
    render 'new', status: :unprocessable_entity
  end
end

#destroyObject



41
42
43
44
45
# File 'app/controllers/infold/attachment_fields_controller.rb', line 41

def destroy
  @attachment_field = AttachmentField.find(params[:id])
  @attachment_field.destroy!
  redirect_to model_attachment_fields_path(@attachment_field.model), status: :see_other, flash: { notice: t('infold.flash.destroyed') }
end

#editObject



25
26
27
28
# File 'app/controllers/infold/attachment_fields_controller.rb', line 25

def edit
  @attachment_field = AttachmentField.find(params[:id])
  @model = @attachment_field.model
end

#indexObject



3
4
5
6
# File 'app/controllers/infold/attachment_fields_controller.rb', line 3

def index
  @model = Model.find(params[:model_id])
  @attachment_fields = @model.attachment_fields.sort_by(&:id)
end

#newObject



8
9
10
11
# File 'app/controllers/infold/attachment_fields_controller.rb', line 8

def new
  @model = Model.find(params[:model_id])
  @attachment_field = @model.attachment_fields.build
end

#updateObject



30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/infold/attachment_fields_controller.rb', line 30

def update
  @attachment_field = AttachmentField.find(params[:id])
  @attachment_field.assign_attributes(post_params)
  if @attachment_field.save
    redirect_to model_attachment_fields_path(@attachment_field.model), flash: { info: t('infold.flash.updated') }
  else
    flash.now[:warning] = t('infold.flash.invalid')
    render 'edit', status: :unprocessable_entity
  end
end