Class: Infold::ShowAssociationsController

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

Instance Method Summary collapse

Instance Method Details

#showObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/infold/show_associations_controller.rb', line 4

def show
  @show_association = ShowAssociation.find(params[:id])
  @view = @show_association.app_view
  @app = @view.app
  association_model = @show_association.model_association.model
  association_model.columns.sort_by(&:seq).each do |column|
    if @show_association.show_association_fields.find { |r| r.model_column_id == column.id }.blank?
      @show_association.show_association_fields.build(
        type: ShowAssociationColumn.name,
        seq: @show_association.show_association_columns.size,
        model_column: column,
        display: false)
    end
  end
  association_model.attachment_fields.each do |attachment_field|
    if @show_association.show_association_fields.find { |r| r.attachment_field_id == attachment_field.id }.blank?
      @show_association.show_association_fields.build(
        type: ShowAssociationAttachmentField.name,
        seq: @show_association.show_association_columns.size,
        attachment_field: attachment_field,
        display: false)
    end
  end
end

#updateObject



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

def update
  @show_association = ShowAssociation.find(params[:id])
  @show_association.assign_attributes(post_params)
  if @show_association.save_with_associations
    redirect_to @show_association, flash: { info: t('infold.flash.updated') }
  else
    @view = @show_association.app_view
    Rails.logger.debug "エラー #{@show_association.errors.full_messages}"
    flash.now[:warning] = t('infold.flash.invalid')
    render status: :unprocessable_entity
  end
end