0

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.

2
  • You probably have Turbo enabled. You may read this thread. stackoverflow.com/questions/73359149/… Also inline JS through <script> is a bit out of scope and I don't have experience with it since Turbo/Stimulus. To me it should run on redirects but there are some edge cases github.com/hotwired/turbo/issues/186 Commented Nov 13, 2022 at 23:15
  • In addition to what @Maxence is saying that HTML is broken - you're missing a </script> end tag. If this is the actual code thats running it will create a syntax error when the JS intrepreter runs into <script>. Commented Nov 14, 2022 at 10:06

2 Answers 2

0

There are unlimited ways to refresh a page - but some helpful aspect of your situation:

1- html tag: <meta http-equiv="refresh" content="30">

w3schools link

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.