0

I want to load my jquery tabs if a certain condition is true. Is it possible to have a ruby if statement embedded in document.ready() or by the time that is processed its too late? Is there a better way to accomplish this?

This doesn't seem to work:

<script>
$(document).ready(function() {
    <% if @event.scheduled.empty? %>
    $( "#tabs" ).tabs();    
    <% end %>   
});
</script>
4

1 回答 1

2

当您在 JQuery 中使用 ruby​​ if 条件时,您需要摆脱这种情况,您可以使用 escape_javascript 标记来实现。尝试这个,

<script>
  $(document).ready(function() {
    <%= escape_javascript(if @event.scheduled.empty?) %>
    $( "#tabs" ).tabs();    
    <% end %>   
  });    
</script>
于 2014-10-15T10:27:03.283 回答