There is a way to put ruby conditions inside javascript block? i.e.
javascript:
var config = {
common_value_1 : 1,
common_value_2 : 2
};
You have 2 options:
ruby sectionThis scenario is better for complex code.
I have a ruby object that I want to make a JSON. So, inside my slim file I'll create a ruby section:
ruby:
myObject = @object.to_json.html_safe
Pay attention to html_safe: it's important to not escape double quotes.
Then you can use myObject inside javascript section:
javascript:
var data = #{myObject};
For simple cases, use the double curly braces inside the javascript section, like stated in @fphilipe answer:
javascript:
var data = #{{@object.to_json}};