# Javascript requests not being routed properly

**URL:** <https://www.ruby-forum.com/t/javascript-requests-not-being-routed-properly/132057>\
**Category:** Rails\
**Created:** [March 16, 2008, 5:50am UTC](https://www.ruby-forum.com/t/javascript-requests-not-being-routed-properly/132057 "2008-03-16T05:50:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumwutdum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@sumwutdum](https://www.ruby-forum.com/u/sumwutdum)\
**Post date:** [March 16, 2008, 5:50am UTC](https://www.ruby-forum.com/t/javascript-requests-not-being-routed-properly/132057/1 "2008-03-16T05:50:30Z")

</div>

I have a file in views/admin/contents/new.js that I would like to be  
returned on a request from a script tag ex:

## If I test out the js request manually, ie entering the js url in the browser, I get the error shown below:

Template is missing

Missing layout layouts/admin.js.erb in view path  
/Users/chris/Documents/Projects/Rails/test\_proj/app/views

* * *

It is **Missing layout layouts/admin.js.erb** that I don’t understand.  
Why is this being routed in this way? It should be  
admin/views/contents/new.js.

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![sumwutdum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@sumwutdum](https://www.ruby-forum.com/u/sumwutdum)\
**Post date:** [March 17, 2008, 6:19pm UTC](https://www.ruby-forum.com/t/javascript-requests-not-being-routed-properly/132057/2 "2008-03-17T18:19:46Z")

</div>

iso … wrote:

> I have a file in views/admin/contents/new.js that I would like to be  
> returned on a request from a script tag ex:
> 
> ## If I test out the js request manually, ie entering the js url in the browser, I get the error shown below:
> 
> Template is missing
> 
> Missing layout layouts/admin.js.erb in view path  
> /Users/chris/Documents/Projects/Rails/test\_proj/app/views
> 
> * * *
> 
> It is **Missing layout layouts/admin.js.erb** that I don’t understand.  
> Why is this being routed in this way? It should be  
> admin/views/contents/new.js.
> 
> Thanks for the help.

I should add that I have no problem obtaining the js files if they are  
not nested in a route, ie.

map.namespace do |admin|  
admin.resources :content\_files  
end

allows me to fetch the new js template file from  
views/admin/content\_files/new.js.erb

Has anyone else had this problem?

---

<div class="post-metadata">

**Author:** ![sumwutdum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@sumwutdum](https://www.ruby-forum.com/u/sumwutdum)\
**Post date:** [April 13, 2008, 8:22pm UTC](https://www.ruby-forum.com/t/javascript-requests-not-being-routed-properly/132057/3 "2008-04-13T20:22:49Z")

</div>

Hi,

I have a similar problem when I use  
layout “alternative\_layout”  
in one of my controllers that needs to call ajax with a template like  
“mytemplate.js.erb”.

Then when running from localhost:3000, it tells me that  
“alternative\_layout.js.erb” is missing. I think the correct template  
should be “mytemplate.js.erb”, and it is there. I can’t figure out why  
it tells me that “alternative\_layout.js.erb” is missing.

My ugly solution is just copy “mytemplate.js.erb” to  
“alternative\_layout.js.erb”, and then it works fine.

Have you found a better solution?

Thanks.

On Mar 15, 11:50 pm, \_\_iso \_\_ [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
