  def set_attachment
    Log.add_info(request, params.inspect)

    return unless request.post?

    created = false

    if params[:id].blank?
      @item = Item.new_info(0)
      @item.attributes = params.require(:item).permit(Item::PERMIT_BASE)
      @item.user_id = @login_user.id
      @item.title = t('paren.no_title')

      [:attachment0, :attachment1].each do |attach|

        next if params[attach].nil? or params[attach][:file].nil? or params[attach][:file].size == 0

        @item.save!
        created = true
        break
      end
    else
      @item = Item.find(params[:id])
    end

    modified = false

    item_attachments = @item.attachments_without_content
    [:attachment0, :attachment1].each do |attach|
      next if params[attach].nil? or params[attach][:file].nil? or params[attach][:file].size == 0

      attachment = Attachment.create(params[attach], @item, item_attachments.length)

      modified = true
      item_attachments << attachment
    end

    if modified and !created
      @item.update_attribute(:updated_at, Time.now)
    end

    render(:partial => 'ajax_item_attachment', :layout => false)

  rescue => evar
    Log.add_error(request, evar)

    @attachment = Attachment.new
    @attachment.errors.add_to_base(evar.to_s[0, 256])

    render(:partial => 'ajax_item_attachment', :layout => false)
  end
The software constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.