New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: Form responses must redirect to another location #11
Comments
Based on this comment it seems you have to return a 422 status code when you want to return HTML after a form submission. Have you tried that? |
Thanks for the answer. This looks like an issue #5 . if form.validate_on_submit():
img = form.img.data
filename = secure_filename(img.filename)
if os.path.splitext(filename)[1] != validate_image(img.stream):
flash('Files content is not valid!', 'danger')
return render_template('create_post.html', form=form) does not work, no messages are displayed, and an error message appears in the JS console. return render_template('create_post.html', form=form), 422 everything works well. |
But this also means that, when using turbo.js, in the standard route pattern like if form.validate_on_submit():
user.set_password(form.password.data)
db.session.commit()
flash('Password was changed. You can log in', 'success')
return redirect(url_for('main.index'))
return render_template('auth/new_password.html', form=form) , you always need to add if form.validate_on_submit():
user.set_password(form.password.data)
db.session.commit()
flash('Password was changed. You can log in', 'success')
return redirect(url_for('main.index'))
elif form.is_submitted():
return render_template('auth/new_password.html', form=form), 422
return render_template('auth/new_password.html', form=form) ? |
I don't think this needs to be done always. My understanding is that this problem only occurrs when you don't have your form inside a |
I am trying to use only to display information about users like index.html: {% block content %}
<div class="container">
<div id="user-actions-info"> <!-- turbo's target -->
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }}" role="alert">{{ message }}</div>
{% endfor %}
{% endif %}
{% endwith %}
</div> in create_app: def live_log_in_info(app):
@user_logged_in.connect_via(app)
def log_in_info(sender, user):
turbo.push(turbo.append(render_template('auth/_user_logged_in.html', user=user), 'user-actions-info'))
@user_logged_out.connect_via(app)
def log_out_info(sender, user):
turbo.push(turbo.append(render_template('auth/_user_logged_out.html', user=user), 'user-actions-info')) |
I'm sorry but I don't understand. Are you using |
I don't use |
@Alexsik76 And have you considered putting the form inside a turbo frame? That eliminates this problem. |
Thanks for your answers and your patience. The |
Hello! As I understand it, there is a problem in the operation of turbo.js when processing a form if it is not valid. In this case, without receiving a redirect, turbo.js generates an error: "Error: Form responses must redirect to another location".
The only working solution for me is to disable turbo-frame in forms: "data-turbo =" false "".
hotwired/turbo-rails#122
Is there another way?
The text was updated successfully, but these errors were encountered: