Search code examples
javascriptruby-on-railsrubyruby-on-rails-3slim-lang

How to write ruby erb tag in slim javascript?


javascript:
  var flash_message = '';

  - if flash.any?


  $(document).ready(function(){
    $(".button-collapse").sideNav();
  });

I want use normal erb tag in javascript area generate by slim. If have flash message, set flash_message = html string generate by rails helper. But I can't use - if flash.any? in javascript: of slim.


Solution

  • Use Text interpolation:

    var flash_message = '#{flash.any? ? flash_to_html_helper(flash) : nil}';