hi as far as i know (i''m new on ror) the file structure of javascript files are: app/views/posts/... public/javascripts/*.js what i understand as a View is final step of the application, the thing that user see, let''s say...the screen. in this sense, javascript in some cases, are also -part of- the "view" for some situations. so, i understand that public/javascript is for general JS code purposes, but in my case i need to build special JS files for every controller. even more, in some cases, i need to build JS files for every action file. in order to mantain the things on its place, i began to build this structure: app/views/posts/edit.html.erb app/views/posts/new.html.erb public/javascripts/posts/edit.js public/javascripts/posts/new.js even when it works, i must say that i find a little disorder. cuz, as i said before, this JS code is more ralated to the "view". so, i really think that this will be a better structure: app/views/posts/edit.html.erb app/views/posts/new.html.erb app/views/posts/edit.js app/views/posts/new.js ¿is there an easy a way to make this structure? ¿how and where i must include these js files? ¿wich is the best rails practice for such a thing? thanks... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
On Mar 3, 1:40 am, Vladimir Prieto <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > even when it works, i must say that i find a little disorder. cuz, as i > said before, this JS code is more ralated to the "view". so, i really > think that this will be a better structure: > > app/views/posts/edit.html.erb > app/views/posts/new.html.erb > app/views/posts/edit.js > app/views/posts/new.js > > ¿is there an easy a way to make this structure? > ¿how and where i must include these js files? > ¿wich is the best rails practice for such a thing? >Rails doesn''t really do much for you here - it''s expecting js can be served out of the document root (ie the public folder) As far as I know you''re pretty much on your own here. One way would be to have a rake task or similar that consolidates all of those small js files into a single all.js file which the user''s browser can download and cache once and for all - only all.js would need to be in public/ javascripts Fred> thanks... > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Or is this way correct? In your helper code like def js_to_be_included %{ <script> function test_function{ ------- } </script> } end Now in your view include this <%= js_to_be_included %> Now call it like test_function Sijo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maybe Matching Threads
- newbie: what is preferred approach for including javascript files?
- How to transfer a javascript value into a symbol used in Ruby on Rails
- javascript tabs not working in rails app
- Rendering a different Javascript file in respond_to
- Sprockets File not Found Exception.