Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 797
wkang Avatar asked Apr 13 '11 08:04

wkang


People also ask

What are .slim files?

Definition of slim file : a file very narrow in proportion to its length.

What is Slim in ruby?

What is Slim? Slim is a fast, lightweight templating engine with support for Rails 3 and later. It has been heavily tested on all major ruby implementations. We use continuous integration (travis-ci).

What is slim Javascript?

Slim is an ultra fast, native and elegant library for Web Components development.

What is Slim css?

Slim is a page-templating language that minimizes markup and syntax. It removes most of the extra "programming-like" symbols from HTML so that your code looks cleaner. Slim also adds if-else statements, loops, includes, and more.


1 Answers

In Slim

javascript:   var all_product_ids = "#{existing_ids.to_json}";   var products_json   = "#{@filter.data.to_json}"; 
like image 57
stonean Avatar answered Sep 17 '22 13:09

stonean