1

I am reading Rails guide and saw this

Rails ships with CoffeeScript by default

OK. If that's the case why's it that when I generate a new rails app, in the javascript assets folder I get application.js and then when I generate a controller I get another file controler_name.coffee? What's the point in keeping 2 extensions and what's the reason they adopted CoffeeScript if not to, say, reduce code lines. Any benefit here?

    1 Answer 1

    1

    application.js is the manifest file, in which you tell Sprockets what Javascript files are to be loaded into your application. Read up on the Asset Pipeline for more details on how it works.

    You can write your JS in application.js and it will run fine, but it's not a good idea as it might degenerate into a big ball of random JS as the app grows.

    The controller_name.coffee files are where your actual application specific CoffeeScript should go, grouped to help you organize JS specific to each controller.

    Note that JS/CS in any controller_name.coffee file loads for all pages by default.

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.