title: How to respond to ajax call in Rails
body: <p>I know there are many questions about that already on stackoverflow but none of them has been useful for me. Here is my ajax code: </p>
  
  <pre><code>function update_schedule($task){
    var taskId = $task.data("taskId"),
      startHour, endHour,
      userId = $('#users').val();
    if( !$task.hasClass('daily-task')){ 
      startHour = getStartHour($task),
      endHour = startHour + (+$task.data('time'));
    }
    console.log(startHour, endHour)
  
     $.ajax({
            url: '/heimdall/update_scheduled_task',
            method: 'POST',
            data: { "task_id": taskId, "start_hour": startHour, "end_hour": endHour, "user_id": userId },
            success: function (){
              console.log("SUCESS!!", data['head'])
            },
            error: function () {
                console.log("FAILURE");
            },
            async: true
      }); 
  }
  </code></pre>
  
  <p>The controller code: </p>
  
  <pre><code>def update_scheduled_task
      scheduled_task = ScheduledTask.find_or_create_by(task_id: params[:task_id])
      scheduled_task.update_attributes(start_hour: params[:start_hour], end_hour: params[:end_hour], task_id: params[:task_id], user_id: params[:user_id])
  
    end
  </code></pre>
  
  <p>I want to return the id of found or created task. I don't know how to send/receive this information. I've read about respond to but still I don't know how to use it in this case.</p>