# How to get rails 3 to respons with js?

**URL:** <https://www.ruby-forum.com/t/how-to-get-rails-3-to-respons-with-js/195761>\
**Category:** Rails\
**Created:** [September 29, 2010, 7:18pm UTC](https://www.ruby-forum.com/t/how-to-get-rails-3-to-respons-with-js/195761 "2010-09-29T19:18:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 29, 2010, 7:18pm UTC](https://www.ruby-forum.com/t/how-to-get-rails-3-to-respons-with-js/195761/1 "2010-09-29T19:18:47Z")

</div>

Hi All,  
Does anyone have experience with rails 3 refusing to return js (or  
some other format) in controller actions that are designed to return  
both html and some other format? I have the following code:

respond\_to :html, :js

def index  
@artist = Artist.find\_by\_url(params[:artist\_id])  
@tour\_dates = TourDate.for\_artist(@artist)  
respond\_with(@tour\_dates)  
end

When I do a js request for this action it renders and returns my  
index.html.erb as the response body, even though i have a nice  
index.js.erb file. Here’s the log:

Started GET “/admin/artists/aube/tour\_dates” for 127.0.0.1 at  
2010-09-29 13:08:07 -0400  
Processing by Admin::TourDatesController#index as JS  
Parameters: {“artist\_id”=\>“aube”}  
…  
Rendered collection (0.0ms)  
Rendered admin/tour\_dates/index.html.erb (2.5ms)  
Completed 200 OK in 266ms (Views: 35.8ms | ActiveRecord: 2.5ms)

Any idea why rails it not handling the non-html formats properly?  
Thanks,  
Sean

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 29, 2010, 7:40pm UTC](https://www.ruby-forum.com/t/how-to-get-rails-3-to-respons-with-js/195761/2 "2010-09-29T19:40:19Z")

</div>

removed\_email\_address@domain.invalid wrote:

> When I do a js request for this action it renders and returns my  
> index.html.erb as the response body, even though i have a nice  
> index.js.erb file. Here’s the log:

What about index.rjs instead of index.js.erb? That should work.
