Search code examples
ruby-on-railsslim-lang

how to embed the result of a Ruby variable in a slim Javscript block


I have a Rails app that uses slim for templating. I'd like to have:

javascript: 
  window.ads.hasMap = ??? # value of show_map 

like in .erb

   window.ads.hasMap = <%=show_map %>;

How would I do this?


Solution

  • According to the docs, it looks like you want:

    javascript: 
      window.ads.hasMap = #{show_map}
    

    That is, wrap your ruby variable or method in #{...}.