app/controllers/cms9/post_fields_controller.rb
def create
      @field = PostField.new(post_field_params)
      @field.user_id = current_user.id

      if PostField.where(name: @field[:name],
                         post_definition_id: @field[:post_definition_id]).blank?
        if %w(select_single select_multiple).include?(@field[:field_type])
          @field.metadata = ''
          values = params[:multi_values]

          values.each_with_index do |value, index|
            if value != '' && index.zero?
              @field.metadata = value
            elsif !index.zero?
              @field.metadata = @field.metadata + ',' + value
            end
          end
        elsif !%w(select_single select_multiple image)
              .include?(@field[:field_type])
          @field.metadata = nil
        end

        if @field.save
          create_post_field_event
          redirect_to edit_post_definition_path(id: @field.post_definition_id)
        else
          render :new
        end
      else
        @field.errors.add(:name, 'of field already exist')
        render :new
      end
    end
def create
      @field = PostField.new(post_field_params)
      @field.user_id = current_user.id

      if PostField.where(name: @field[:name],
                         post_definition_id: @field[:post_definition_id]).blank?
        if %w(select_single select_multiple).include?(@field[:field_type])
          @field.metadata = ''
          values = params[:multi_values]

          values.each_with_index do |value, index|
            if value != '' && index.zero?
              @field.metadata = value
            elsif !index.zero?
              @field.metadata = @field.metadata + ',' + value
            end
          end
        elsif !%w(select_single select_multiple image)
              .include?(@field[:field_type])
          @field.metadata = nil
        end

        if @field.save
          create_post_field_event
          redirect_to edit_post_definition_path(id: @field.post_definition_id)
        else
          render :new
        end
      else
        @field.errors.add(:name, 'of field already exist')
        render :new
      end
    end
rubocop:disable all