0

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?

Nima
  • 3,309
  • 6
  • 27
  • 44
ibpix
  • 179
  • 1
  • 9
  • 1
    https://stackoverflow.com/questions/5646315/how-to-embed-dynamic-ruby-code-to-javascript-section-in-slim-templates, https://stackoverflow.com/questions/17794403/ruby-inside-javascript-block-slim-template/25865643, https://github.com/slim-template/slim/issues/426 should all help – engineersmnky Aug 30 '21 at 16:32

1 Answers1

1

According to the docs, it looks like you want:

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

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

JohnP
  • 1,229
  • 6
  • 24