0

I have a question. Maybe little stupid but I want to be sure. I know, how to hand on code from Ruby to JS and work on it. I mean js.erb file.
Simple example:

<% ruby_var = 15 %>
var jsVar = <%= ruby_var %>;
// jsVar => 15

It works.

On the same js.erb file I would like to do it reverse:

var jsVar = 15;
<% ruby_var = jsVar %>

I have no idea how I can do it. Is it possible?
Please advice.

0

1 Answer 1

0

You can't do this at all and it's never needed.

Javascript is a client side code, that will be executed in client's browser. This code will NOT be executed on server, so you can't get anything in your ruby variable. When JavsScript will be executed on client side, there will be no ruby at all (all ruby scripts will be already turned into plain HTML/CSS/JS

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

1 Comment

@Damian Have you answered your question? Do you need any help how you get rid of need to save JS value into ruby variable?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.