Skip to content

Instantly share code, notes, and snippets.

@jcdavison
Created January 5, 2023 16:02
Show Gist options
  • Select an option

  • Save jcdavison/93b7424c17b015590daba704e5f7fb9d to your computer and use it in GitHub Desktop.

Select an option

Save jcdavison/93b7424c17b015590daba704e5f7fb9d to your computer and use it in GitHub Desktop.

assuming we have a create endpoint that has something like

 def create
    @candidate = Candidate.new(candidate_params)

    @candidate.user_id = current_user.id
    @candidate.save!

    respond_to do |format|
      format.turbo_stream
    end
  rescue
    respond_to do |format|
      format.turbo_stream
    end
  end

and we have a stimulus controller like

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {

reset(event) {
  this.element.reset()
}

}

question: in the case that the candidate (or whatever) isn't saved, sure we understand how to send a different turbo partial back to the browser, but how do we communicate to the stimulus controller that the object wasn't created correctly? And therefore, don't reset the form, let the user do that so they can remember what they wrote and fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment