Hi, I am making a new little web site. Each page has it''s own css/js files apart. I want to include any of that css/js files on the application layout depending on wich page will be loaded. For example if "upload" page will be loaded, the application layout should just include the "upload.css" and the "upload.js". I tryed, using an if-else aproach so, using if stataments in the app layout i just load the files i need, for example: if @page == "upload" # include upload.cc else ... end I think this aproach is kinda ugly, so i used another one, in this case, i made multiple layouts for any of the pages i need to load, but this aproach will repeat a lot of my html code, for example: header and footer will be the same on each page, so making a change in any of these parts will require to modify all the pages layouts that i have, this is too much work. Any ideas of how can i solve this? (is there any other way to do this) Cheers, Shirkavand
something like this should probably work.... in application/layout.html.erb <%= yield :javascripts %> in the individual views: <% content_for :javascripts do %> <%= javascript_include_tag "js_for_page_in_question" %> <% end %> On May 18, 1:22 am, fRAnKEnSTEin <shirkav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I am making a new little web site. Each page has it''s own css/js files > apart. I want to include any of that css/js files on the application > layout depending on wich page will be loaded. For example if "upload" > page will be loaded, the application layout should just include the > "upload.css" and the "upload.js". > > I tryed, using an if-else aproach so, using if stataments in the app > layout i just load the files i need, for example: > > if @page == "upload" > # include upload.cc > else > ... > end > > I think this aproach is kinda ugly, so i used another one, in this > case, i made multiple layouts for any of the pages i need to load, but > this aproach will repeat a lot of my html code, for example: header > and footer will be the same on each page, so making a change in any of > these parts will require to modify all the pages layouts that i have, > this is too much work. > > Any ideas of how can i solve this? (is there any other way to do this) > > Cheers, > > Shirkavand
Hi Shirkavand, To avoid repeating html code, you can use application layout file (/ app/views/layouts/application.html.erb). Here you can specify any markup you want to be applied for all the pages in your app. If the layouts folder doesn''t contain layout file for some controller, appllication layout file will be used. Why do you want to use individual css and js files for each page? Isn''t it simpler to use one css and js files if you are developing little web site? Regards, Bob On May 18, 9:22 am, fRAnKEnSTEin <shirkav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I am making a new little web site. Each page has it''s own css/js files > apart. I want to include any of that css/js files on the application > layout depending on wich page will be loaded. For example if "upload" > page will be loaded, the application layout should just include the > "upload.css" and the "upload.js". > > I tryed, using an if-else aproach so, using if stataments in the app > layout i just load the files i need, for example: > > if @page == "upload" > # include upload.cc > else > ... > end > > I think this aproach is kinda ugly, so i used another one, in this > case, i made multiple layouts for any of the pages i need to load, but > this aproach will repeat a lot of my html code, for example: header > and footer will be the same on each page, so making a change in any of > these parts will require to modify all the pages layouts that i have, > this is too much work. > > Any ideas of how can i solve this? (is there any other way to do this) > > Cheers, > > Shirkavand
HI, Thank you very much pharrington and bob for your fast replay. Ok i am gonna test pharrington aproach and let you know what happened. Bob: yes, you are right, this app is little so i can use just one js/ css file. The problem is that i have developed in the past some other medium size sites, and they have a lot of javascript code that are totally different for each page, so creating a unique js file will make each page to load a lot of js code that will not use. So i just realize that i want to change this, and i wanted to start my new little site with this change done. Cheers.