I have a html page with a script, It looks like
<html>
</html>
<script>
<script>
The page needs to run this script to display the content correctly.
But when I redirect to this page with following code:
redirect_to user_trips_path(params[:user_id])
I noticed that it will not refresh the page. If I refresh the page manually it will display the content correctly.
My question is how to make this automatic?
I try to google this question.
CodePudding user response:
There are unlimited ways to refresh a page - but some helpful aspect of your situation:
1- html tag: <meta http-equiv="refresh" content="30">
put it on your html or inject it with JS after page load.
2- JavaScript or jQuery:
How do I refresh a page using JavaScript?
3- if you have View on your Rails app you can create a route and method for run sample_name.js.erb and then in this file with some JS code you can open your partial and main .html.erb file
--
If after the first time you want to run a script to start to refresh the page you can redirect users with special param in user_trips_path and then in your JS code check if its present then run your code.
CodePudding user response:
In Rails 7
If you want to disable Turbo Drive you can set Turbo.session.drive = false
in your javascript/application.js file.
import { Turbo } from "@hotwired/turbo-rails"
Turbo.session.drive = false
=> It will reload the page while navigating