How to embed dynamic Ruby code to "javascript" section in Slim templates?

wkang picture wkang · Apr 13, 2011 · Viewed 30.3k times · Source

One way:

javascript_tag do
  == "var all_product_ids = #{existing_ids.to_json};"
  == "var products_json   = #{@filter.data.to_json};"

or:

= %Q{
var all_product_ids = #{existing_ids.to_json};
var products_json   = #{@filter.data.to_json};
}

are there any better solutions for this?

Answer

stonean picture stonean · Jul 25, 2011

In Slim

javascript:
  var all_product_ids = "#{existing_ids.to_json}";
  var products_json   = "#{@filter.data.to_json}";