views:

38

answers:

3

In the public folder we have stylesheets, javascripts and images.

I want to add a front-end feature that has it's own css, js and images, but according to this hierarchy i have to store them like this:

stylesheets/calendar/main.css
javascripts/calendar/cal.js
javascripts/calendar/cal2.js
images/calendar/front.jpg
images/calendar/button1.jpg
images/calendar/button2.jpg
images/calendar/button3.jpg

I don't like that I split the feature up at all.

Is there a way to organize files per feature instead?

calendar/stylesheets/main.css
calendar/javascripts/cal.js
calendar/javascripts/cal2.js
calendar/images/front.jpg
calendar/images/button1.jpg
calendar/images/button2.jpg
calendar/images/button3.jpg

That would be a better structure, following OOP pattern.

+1  A: 

You can organize stuff in public folder any way you want. Only difference is that when you use some of the Rails helpers working with paths to files in public folder you have to specify where those files are (if you moved them out of their default location).

For example, in case of stylesheet_link_tag you'd have to do something like:

stylesheet_link_tag '/calendar/stylesheets/main.css'
Slobodan Kovacevic
+2  A: 

Ya, Slobodan Kovacevic is right,

you can organize to anywhere,

another way to do is,

stylesheet_link_tag "#{RAILS_ROOT}/calendar/stylesheets/main.css"

follow this procedure when u get problem on

stylesheet_link_tag '/calendar/stylesheets/main.css'

u need to optimize this another way by using Helper method.

calling every file from helper and using it on rails.

Senthil Kumar Bhaskaran
+2  A: 

As the others mention, you can do pretty much anything you like.

This is the system we are currently using:

Place files inside directories corresponding to the "layout" they are applicable to:

/web/images
/web/javascripts
/web/stylesheets

/mobile/images
/mobile/javascripts
/mobile/stylesheets

/admin/etc

Top-level directories (/images /javascripts /stylesheets) are used for elements that are genuinely common (such as jquery, css reset scripts and standard logos).

Client-side library packages be maintained in their own directory rather than spread out into the standard Rails directories. This greatly aids long term maintenance.

Using colorbox as an example:

Rather than:

 /javascripts/colorbox.js
 /stylesheets/colorbox.css

We have:

 /web/libs/colorbox/colorbox.js
 /web/libs/colorbox/colorbox.css
Toby Hede
And you load them manually with: "stylesheet_link_tag '/web/libs/colorbox/colorbox.css'"?
never_had_a_name
Actually, use asset_packager to combine everything into a smaller number of files and use custom stylesheet_link_tag to handle.
Toby Hede