I've got a form that's submitted like so:
class PreferenceForm
constructor: (preference_form) ->
@preference_form = preference_form
@preview_update_button = @preference_form.find $("[data-behavior='preview-update-button']")
@submit_url = @preference_form.attr('action')
@setEvents()
setEvents: ->
@preference_form.on "submit", @handleSubmit
handleSubmit: (event) =>
event.preventDefault()
console.log @submit_url
$.ajax(
url: @submit_url,
method: "PATCH"
dataType: "JSON"
data: @preference_form.serialize()
success: @handleSuccess
)
The console logs @submit_url as, /user_preferences/#
which is correct. However, when I actually try to submit the form, it sends the PATCH request to the current page instead of the url I'm trying to send it to.
What causes this behavior to happen? How can I make it behave the way I intend?
Everything is instantiated like this:
class CertificatePreviewer
constructor: (certificate_previewer) ->
@certificate_previewer = certificate_previewer
@preference_form = new PreferenceForm @certificate_previewer.find $("[data-behavior='preference-form']")
jQuery ->
new CertificatePreviewer $("[data-behavior='certificate-previewer']")