turbo2oh
turbo2oh

Reputation: 2879

jquery tabs and conditional ruby code on document.ready()

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>

Upvotes: 0

Views: 122

Answers (1)

user3928433
user3928433

Reputation: 21

As you are using ruby if condition in JQuery, you need to come out of that, you can make that from using escape_javascript tag. try this,

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

Upvotes: 2

Related Questions