3

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 syntax which makes this a little more difficult.

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

^ doesn't error but doesn't even include the file

javascript_tag[type="text/x-mathjax-config"] javascript code here

^ throws an error

I'm hoping to avoid breaking the file away from slim.

Ruby version 1.9.3 Rails version 3.2.3

ylluminate
  • 12,102
  • 17
  • 78
  • 152
user1751210
  • 31
  • 1
  • 3

2 Answers2

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.

Jim Wrubel
  • 4,031
  • 1
  • 17
  • 12
1

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

<script src="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).

Alexander Presber
  • 6,429
  • 2
  • 37
  • 66