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”
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)
something like this should probably work…
in the individual views:
<% end %>
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?
Thank you very much pharrington and bob for your fast replay.
Ok i am gonna test pharrington aproach and let you know what
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
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.
Yes! it worked just great!!