I''m curious about a conflict between railscasts and rails 3.1 documention. Do I put javascript code into application.js in the assets folder or not? And what''s the ramifications of either approach? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
As it says in application.js: " // This is a manifest file that''ll be compiled into including all the files listed below. // 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. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
So I could put my code into another file "foo.js" and ''require'' it in application.js. I believe these other .js files would be in the assets directory to be picked up? On 1/12/12 11:57 AM, Linus Pettersson wrote:> As it says in application.js: > " > // This is a manifest file that''ll be compiled into including all the > files listed below. > > // 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. > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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. 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. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 13, 2012, at 2:00 PM, Linus Pettersson wrote:> 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. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
djangst
2012-Jan-13 19:43 UTC
How should javascript assets be included? (was Re: RailsCasts)
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. On Jan 13, 2:00 pm, Linus Pettersson <linus.petters...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > Cheers! > Linus-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
djangst
2012-Jan-13 19:48 UTC
Re: How should javascript assets be included? (was Re: RailsCasts)
And I''m also interpreting "(don''t) add code directly here" as not to uncomment require_tree, because isn''t uncommenting equivalent to adding? But again other sources say to use require_tree to include separate files in that directory. On Jan 13, 2:43 pm, djangst <djan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Javier Quarite
2012-Jan-13 19:49 UTC
Re: How should javascript assets be included? (was Re: RailsCasts)
On Fri, Jan 13, 2012 at 2:43 PM, djangst <djangst-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > >I guess if .. lets say you have 2 files tasks.js activities.js if you put require_tree inside your application.js it will include that files using this <%= javascript_include_tag "application" %> but if you just only need tasks.js then <%= javascript_include_tag "tasks" %> and that''s all Javier -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.