1

How can I evaluate an instance variable from within the javascript view (for use by another AJAX process)?

I would like do a conditional evaluation (in my test.js.erb file) of an instance variable defined in a controller method.

Controller method:

def test
  @var = 100
end

.JS View:

if (<%= @var=100 %>) {
  alert("var: " + <%= @var %>);
} else {
  alert("failed");
}

Do I need to build the entire conditional check within erb tags?

1 Answer 1

1
if (<%= @var %> === 100 ) {...}
Sign up to request clarification or add additional context in comments.

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.