Why do rails use the .js.coffee extension for coffeescript files when they cannot contain javascript code?

I found this to be quite misleading, as I thought it suggested that such files might include a mixture of javascript and coffeescript code. Is there something very important that I am missing?

+5
source share
2 answers

It is common practice in Rails templates have extensions such as .js.coffee, .html.erb, .html.haml, etc.

If I remember correctly, Rails interprets these extensions as .[format].[builder]it uses this knowledge to do two things:

  • [format], , Accept;
  • [builder] .
+10

javascript, .

- `function(){ do something };` .

+1

All Articles