# Javascript file path

**URL:** <https://discuss.rubyonrails.org/t/javascript-file-path/61884>\
**Category:** rubyonrails-talk\
**Created:** [December 5, 2011, 7:05pm UTC](https://discuss.rubyonrails.org/t/javascript-file-path/61884 "2011-12-05T19:05:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [December 5, 2011, 7:05pm UTC](https://discuss.rubyonrails.org/t/javascript-file-path/61884/1 "2011-12-05T19:05:54Z")

</div>

Hello,

I googled for it but did not find satisfied answer. Problem is that i have a javascript file which need to be loaded on only one page. Also, i am using recursive =\> true with javascript\_include\_tag in layout file.

So, what i have done is that i moved javascript file to public directory and introduced content\_for :head functionality into the view which will pick the script from this public directory.

Question is: How to find javascript file's full path in the view?

Thanks in advance. - Hemant

---

<div class="post-metadata">

**Author:** ![Colin\_Law1](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Colin\_Law1](https://discuss.rubyonrails.org/u/Colin_Law1)\
**Post date:** [December 5, 2011, 8:48pm UTC](https://discuss.rubyonrails.org/t/javascript-file-path/61884/2 "2011-12-05T20:48:04Z")

</div>

> Hello,
> 
> I googled for it but did not find satisfied answer. Problem is that i have a javascript file which need to be loaded on only one page. Also, i am using recursive =\> true with javascript\_include\_tag in layout file.
> 
> So, what i have done is that i moved javascript file to public directory and introduced content\_for :head functionality into the view which will pick the script from this public directory.
> 
> Question is: How to find javascript file's full path in the view?

If the file is public/path/to/file.js then use the url /path/to/file.js (note the leading /).

Colin

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [December 6, 2011, 11:55am UTC](https://discuss.rubyonrails.org/t/javascript-file-path/61884/3 "2011-12-06T11:55:07Z")

</div>

Hello Clan,

Thanks for your reply. Actually i have the js file in "script" directory not in "public" directory.

Is it ok if i do:- root\_url + "/script/file\_name.js" ?

- Hemant

clanlaw wrote in post #1035231:

---

<div class="post-metadata">

**Author:** ![Colin\_Law1](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Colin\_Law1](https://discuss.rubyonrails.org/u/Colin_Law1)\
**Post date:** [December 6, 2011, 12:15pm UTC](https://discuss.rubyonrails.org/t/javascript-file-path/61884/4 "2011-12-06T12:15:07Z")

</div>

> Hello Clan,
> 
> Thanks for your reply. Actually i have the js file in "script" directory not in "public" directory.
> 
> Is it ok if i do:- root\_url + "/script/file\_name.js" ?

If you look at my reply you will see that will look for public/script/file\_name.js. Provided the file is there that will be ok. Why do not just try it and see?

Colin
