Skip to content Skip to sidebar Skip to footer

Custom Javascript Type With Rails And Slim

In Rails, both the javascript_tag and javascript_include_tag render the type attribute as type='text/javascript' I need to customize this attribute. Our application uses Slim s

Solution 1:

Since you are modifying the type attribute you would either need to override the javascript_tag helper or write your own for that to work. This syntax isn't as elegant but should work:

script src=asset_path("mathjax_config") type="text/x-mathjax-config"

Note that this is slim/haml syntax - YMMV in erb.

Solution 2:

The file not being included is not Slims fault. Slim is agnostic to the content of the attributes, so it will happily render

script src="mathjax_config"type="text/x-mathjax-config"

into

<scriptsrc="mathjax_config"type="text/x-mathjax-config"></script>

Also, as far as I know, the browsers should happily load scripts with types other than "text/javascript" and you should be able to access them using their id.

Your approach is correct and the script not being included must have a different reason (like the file specified in src cannot be found).

Post a Comment for "Custom Javascript Type With Rails And Slim"