简体   繁体   English

如果在js.erb中确认

[英]If confirm in js.erb

I need something like this to work: 我需要这样的工作:

Show.erb.js: Show.erb.js:

if (confirm('Delete cart?')) { 
  <%@current_cart.reset%>
  $('.cartbadge').replaceWith('<%= j render :partial => "layouts/cartbadge"%>');
}

but the erb portion of the code is always excecuting 但代码的erb部分总是优秀的

any ideas? 有任何想法吗?

Because the code <%@current_cart.reset%> will be executed when the erb be interpretered. 因为代码<%@current_cart.reset%>将在erb被解释时执行。

You have to use ajax like: 你必须使用ajax:

if (confirm('Delete cart?')) { 
  $.post('<%= reset_cart_path(@current_cart) %>', function() {
      $('.cartbadge').replaceWith('<%= j render :partial => "layouts/cartbadge"%>');
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM