Reputation: 9415
Is there a way to pass a Javascript variable to a Rails path?
For example, I have in my html.erb file:
<script>
for (i=1, i< numSteps, i++){
var step = i
td.innerHTML = <%= project_step_path(@project, step) %>
}
</script>
But this doesn't work since step is a Javascript variable.
Upvotes: 0
Views: 377
Reputation: 944432
In this case, the Ruby will run on the server. It will generate some text. That text is sent to the browser. The browser will parse it as HTML and JS.
You can't do bi-directional synchronous communication in a single HTTP request/response.
So no.
Each time you want to send data from client side JavaScript to server side Ruby you need to issue a new HTTP request.
Issuing such a request can be done by:
location
src
Upvotes: 3
Reputation: 207557
They can not run together.
Upvotes: 2