Hello there,
I’m trying to event.preventDefault()
on a specific form after form submission, I have tried executing javascript code from my create.js.erb file for the create action but this doesn’t work. None of the code in there get’s executed.
I’m using the form_with tag to render my form and I have tried adding the local: true, remote: true (I read somewhere that this was unnecessary because it comes with this property remote: true by default) property to it but none worked.
Here’s how my create action looks like:
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.js
format.json { render json: @user, status: :created, location: @user }
else
format.js
format.json { render json: "cool", status: :unprocessable_entity }
end
end
Thank you for your assistance, any help is much appreciated!