title: rails controller respond_to if/else based on action is successful/not
body: <p>How could I use conditional based on the success of this custom action both for html and js. With basic actions (update, create) works perfectly but here I could not pull off the if/else statement properly, so I have it without checking if the action is successful</p>
  
  <p>With the format.js form I'm using AJAX and complete.js.erb. </p>
  
  <p>controller</p>
  
  <pre><code>def complete
    @task.update_attribute(:completed_at, Time.now)
    respond_to do |format|
      format.html { redirect_to completed_tasks_user_tasks_path(current_user), notice: "Task completed!" }
      format.js
    end
  end
  </code></pre>
  
  <p>view</p>
  
  <pre><code>&lt;% if task.completed_at == nil %&gt;
    &lt;%= link_to complete_user_task_path(id: task.id), action: :complete, remote: true, method: :patch do %&gt;
      &lt;i class="fa fa-check"&gt;&lt;/i&gt;
    &lt;% end %&gt;
  ......
  </code></pre>