如何在咖啡脚本中测试 ruby 变量?我正在更新一个 Rails 遗留应用程序,并尝试在第一步中保持原始格式的关闭。有了.js.erb
,我可以简单<%= if @var %>
地实现我所需要的。
Bellow 是两次错误尝试的视图代码:
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}")
在操作中,正在测试的变量是一个布尔值:
@review_change_needs_refresh = params[:review_change_needs_refresh] == 1
我在咖啡脚本文件的第一行收到以下错误:
ActionView::Template::Error (SyntaxError: unexpected {):
那么,如何在咖啡脚本中测试红宝石变量?