# Overriding default image, stylesheet and javascript paths

**URL:** <https://www.ruby-forum.com/t/overriding-default-image-stylesheet-and-javascript-paths/185838>\
**Category:** Rails\
**Created:** [March 26, 2010, 10:53pm UTC](https://www.ruby-forum.com/t/overriding-default-image-stylesheet-and-javascript-paths/185838 "2010-03-26T22:53:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cult\_hero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e56c9b/32.png) [@cult\_hero](https://www.ruby-forum.com/u/cult_hero)\
**Post date:** [March 26, 2010, 10:53pm UTC](https://www.ruby-forum.com/t/overriding-default-image-stylesheet-and-javascript-paths/185838/1 "2010-03-26T22:53:43Z")

</div>

Is there some way to override the paths for images, stylesheets and  
javascripts without monkey patching? (Rails 3 Beta)

I just looked at asset\_tag\_helper.rb and I see this:

def stylesheet\_path(source)  
compute\_public\_path(source, ‘stylesheets’, ‘css’)  
end

Unless I’m missing something in the way the code works, that seems  
hard coded to me. Am I stuck using the directories /images, /  
stylesheets and /javascripts instead of something more concise like /  
img, /css and /js if I opt to use the helpers?

---

<div class="post-metadata">

**Author:** ![cult\_hero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e56c9b/32.png) [@cult\_hero](https://www.ruby-forum.com/u/cult_hero)\
**Post date:** [March 26, 2010, 11:37pm UTC](https://www.ruby-forum.com/t/overriding-default-image-stylesheet-and-javascript-paths/185838/2 "2010-03-26T23:37:37Z")

</div>

It’s hardcoded as you say. Being able to configure these paths would  
really  
be a good addition to the core if you were to write this as a new  
feature.

/Lasse

2010/3/26 cult hero [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![cult\_hero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e56c9b/32.png) [@cult\_hero](https://www.ruby-forum.com/u/cult_hero)\
**Post date:** [March 26, 2010, 11:41pm UTC](https://www.ruby-forum.com/t/overriding-default-image-stylesheet-and-javascript-paths/185838/3 "2010-03-26T23:41:08Z")

</div>

I might fix that myself. Seems like it would be easy enough. I found a  
similar annoyance today too. (I’ll post that in a moment.)

---

<div class="post-metadata">

**Author:** ![cult\_hero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e56c9b/32.png) [@cult\_hero](https://www.ruby-forum.com/u/cult_hero)\
**Post date:** [March 27, 2010, 11:39am UTC](https://www.ruby-forum.com/t/overriding-default-image-stylesheet-and-javascript-paths/185838/4 "2010-03-27T11:39:46Z")

</div>

Colin,

Yeah â€“ but it should be possible to use your own conventions if that’s  
what  
you want, even though the recommendation is to use the built-in  
conventions.

Regarding plugins and copying, Rails has configured paths, like  
config.javascripts\_dir and config.stylesheets\_dir.

/Lasse

2010/3/27 Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![cult\_hero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e56c9b/32.png) [@cult\_hero](https://www.ruby-forum.com/u/cult_hero)\
**Post date:** [March 27, 2010, 9:55am UTC](https://www.ruby-forum.com/t/overriding-default-image-stylesheet-and-javascript-paths/185838/5 "2010-03-27T09:55:36Z")

</div>

On 26 March 2010 22:36, Lasse B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It’s hardcoded as you say. Being able to configure these paths would really  
> be a good addition to the core if you were to write this as a new feature.
> 
> /Lasse
> 
> 2010/3/26 cult hero [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> > Is there some way to override the paths for images, stylesheets and  
> > javascripts without monkey patching? (Rails 3 Beta)

Do some plugins copy scripts and css to those folders? If so do they  
ask rails where to put them or just assume the conventional names?

I am not convinced it would be a good thing to use alternative names  
just for aesthetic reasons. Rails is all about convention after all.  
One does not like all the conventions but it is better to stick to  
them when possible.

Colin

---

<div class="post-metadata">

**Author:** ![cult\_hero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e56c9b/32.png) [@cult\_hero](https://www.ruby-forum.com/u/cult_hero)\
**Post date:** [March 29, 2010, 10:16pm UTC](https://www.ruby-forum.com/t/overriding-default-image-stylesheet-and-javascript-paths/185838/6 "2010-03-29T22:16:19Z")

</div>

On 29 March 2010 19:15, cult hero [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> problems for now and when I have time on the weekend or something,  
> I’ll see about making some modifications and submitting actual  
> patches. (There are a few other areas in the view helpers to inject  
> some things I don’t much care for that require similar methods.)
> 
> This isn’t necessarily purely about convention, especially when you’re  
> integrating Rails into an existing infrastructure. Symlinks might do  
> the job… but I’m not in love with the idea. (And let’s face it, I’m  
> a control freak about certain aspects of my apps, plain and simple.)

If you are not using ActiveRecord and think the view helpers are  
rubbish and don’t want to stick to the conventions, I am interested in  
knowing what benefits you are getting from rails. (No criticism  
implied, we are all entitled to work the way we want to.)

Colin

---

<div class="post-metadata">

**Author:** ![cult\_hero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e56c9b/32.png) [@cult\_hero](https://www.ruby-forum.com/u/cult_hero)\
**Post date:** [March 29, 2010, 8:16pm UTC](https://www.ruby-forum.com/t/overriding-default-image-stylesheet-and-javascript-paths/185838/7 "2010-03-29T20:16:20Z")

</div>

The reason I didn’t use Rails 2 was because of too much convention. (I  
didn’t want to use ActiveRecord, for one thing.) There is a point  
where too much convention starts to inhibit what I do and what I want.  
It might be fine for others, but that’s why I prefer some level of  
configuration with sensible defaults rather than a method where a path  
is hardcoded. In general, I find that hardcoding something like that  
isn’t good practice.

I’m finding that the view helpers are probably the weakest area in  
this regard. It’s not a biggie though. Monkey patching has fixed the  
problems for now and when I have time on the weekend or something,  
I’ll see about making some modifications and submitting actual  
patches. (There are a few other areas in the view helpers to inject  
some things I don’t much care for that require similar methods.)

This isn’t necessarily purely about convention, especially when you’re  
integrating Rails into an existing infrastructure. Symlinks might do  
the job… but I’m not in love with the idea. (And let’s face it, I’m  
a control freak about certain aspects of my apps, plain and simple.)
