I have a controller with an action that is being hit remotely, after which my controller_action.js.erb file is run.
Within my controller’s action, I am setting a variable @successful = true|false (true|false based on the return value of a function).
Within my javascript file, I want to say if @successful and either alert that the action was successful or alert that it was not.
Any idea how to do this?
I speak HAML usually, so this might not be exactly correct:
In HAML, it would be:
Alternatively, you could do this:
(ERB)
(HAML)
The first option will always render all your JS code on the client side, the only difference being if
trueorfalseis in theifclause.The second option will conditionally only render the JS code for the true or false case.