Ruby on Rails - Partial with random variable -


I partially present this in my opinion:

   & gt; ");});}); & Lt; / Script & gt;  

Partial render is fine, but in my part, I get a random variable

  & lt;% random_id = rand (9999999)% & gt;  

The strange thing is that I click on that button to partially render, random variables are the same, as it is generated once and again gets done again This is a normal behavior and if so, what can I do to avoid it?

is partly sung at the server side and then in the Dom X bar on the client side This is the reason that the random value is always the same. You can either generate random values ​​by using JS:

  1. Make server-side action calls to another partial render
  2. Create some type of server-side JSON API that produces random values ​​

Note (not the root cause of the above problem, but worth mentioning): If you type in some type Using the cache (like), partial content also unchanged on new requests May be, in this case, you can take in the generation of random numbers controller.


Comments