Do I put javascript code into application.js in the assets folder or not?
And what's the ramifications of either approach?
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file."
I find it good to put the code in different files. It makes it easier to find the correct code when debugging.
I believe these other .js files would be in the assets directory to be
picked up?
> --
> You received this message because you are subscribed to the Google
> Groups "Ruby on Rails: Talk" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-/5lOOaMurUM8J.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> That is correct. The .js (or .js.coffee if using coffeescript) files should be in app/assets/javascript/.
>
> You could use require tree which is specified from the beginning and will include all javascript files. I do prefer to require each file separately though as it gives me more control.
Especially important if you are requiring files in a particular order. Require tree sorts them in *alphabetical* order, which can play merry hob with your library code (libraries usually have to come first, in a particular order).
Walter
>
> Cheers!
> Linus
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/MpHSG8PaijgJ.
I find it confusing, because the language in application.js indicates
that separate javascript files need only be included in that directory
and they'll automatically be compiled, while other sources say files
must be specifically required.
In fact application.js says "not advisable to add code directly here,"
which I read as "don't do your requiring here, pal," implying that it
isn't necessary.
Guides didn't make it any clearer.