How can I test a ruby variable in coffeescript? I'm updating a rails legacy application and trying to keep the closes of the original format I can in the first step. With .js.erb
, I could simply do <%= if @var %>
to achieve what I need.
Bellow is the code of the view with two wrong tries:
if @review_change_needs_refresh # Don't work
# if "#{@review_change_needs_refresh}" == "true" Don't work too
location.reload()
else
button_div_id = "#ManagedWorkFor#{@work.class.to_s}#{@work.id}"
label_div_id = "#chat_#{@managed_work.to_language_id}_label"
$(button_div_id,"#{escape_javascript(render(:partial => "/managed_works/managed_work", :object=>@work))}")
if @checkbox_label.any?
for element in $("##{label_div_id}") then do => $("##{label_div_id}", "#{@checkbox_label}")
On the action, the variable that is being tested is a boolean:
@review_change_needs_refresh = params[:review_change_needs_refresh] == 1
I get the following error on the first line of the coffeescript file:
ActionView::Template::Error (SyntaxError: unexpected {):
So, How can I test a ruby varaible in coffeescript?