title: Rails 6 update attributes only if params exist
body: <p>I've got <code>event</code> model which <code>belongs_to :user</code> and have fields: <code>name, start_at, end_at, duration, status</code>. In my controller I want to allow user to update 3 of them: <code>start_date, end_date, duration</code> like below:</p>
  <pre><code>class EventsController
    before_action :set_user, only: [:update]
    before_action :set_event, only: [:update]
    attr_reader :event, :user
    
    def update
      ::Events::Update.new(event, params.permit(:start_date, :end_date, :duration, :user_id, :id)).call
    end
  
    private
  
    def set_event
      @event = user.events.find(params[:id])
    end
  
    def set_user
      @user = User.find(params[:user_id])
    end
  end
  </code></pre>
  <p>To update <code>Event</code> record I'm using below service:</p>
  <pre><code>module Events
    class Update
      attr_reader :params, :event
  
      def initialize(event, params)
        @event = event
        @params = params
      end
  
      def call
        event.update!(
          start_date: params[:start_date],
          end_date: params[:end_date],
          duration: params[:duration]
        )
      end
    end
  end
  </code></pre>
  <p>How to handle situation when e.g. <code>start_date</code> and <code>end_date</code> are not provided (user won't change it) and user to passed only <code>duration</code> to change this value? in current implementation I'm getting an error:</p>
  <pre><code>ActiveRecord::NotNullViolation (PG::NotNullViolation: ERROR:  null value in column &quot;start_date&quot; of relation &quot;events&quot; violates not-null constraint
  </code></pre>