respond_to not working with RJS in rails?

I just created a new rails app to test this out, using edge rails. I
have one controller with one action. The action has both .rhtml and .rjs
views. I put this in the action:

respond_to do |format|
  format.html
  format.js
end

When I send an AJAX request from the html view to that action the
response is the rhtml template, not the rjs template. When I change it
to the following it works:

respond_to do |format|
  format.html
  format.js { render :template => "index.rjs" }
end

That works fine.

It was working fine a few months ago, now all of a sudden it doesn't. Do
I need to define a response for rjs?

I have no plugins, nothing, this is a completely clean and fresh rails
app.

Thanks for your help.

Ben Johnson wrote:

When I send an AJAX request from the html view to that action the
response is the rhtml template, not the rjs template. When I change it
to the following it works:

respond_to do |format|
  format.html
  format.js { render :template => "index.rjs" }
end

First of all, your post help me solve a similar problem, so thank you!

Then I can hopefully help you, because I know exactly when this problem
suddenly occured for me:

I use the above in a installation of the Beast forum. And it has worked
fine while running Rails v. 1.2.6

When I upgraded to Rails 2.0.2 it simply stopped working - until I
applied your solution minutes ago.

So: What version of Rails are you running?

- Carsten

Seeing as you're on Rails 2.0+, try naming your files:

index.html.erb
index.js.rjs

That fixed the problem.

Did they really change the naming format for views? So this is the
"right" way to name your views now? Is there any article about this or
something. Thats kind of a big change to not announce, but maybe I
missed the announcement.

Yes, I believe this change was widely advertised. It's now
"action.format.language"

Ex.:

index.html.erb # use Erb
index.html.haml # use Haml
index.html.mab # use Markaby
index.iphone.erb # serve iPhone content if MimeType is aliased and
user agent is detected

Is rhtml gone, I was under the impression that was erb.

Although it was also widely advertised, that the old naming convention
still would be in use.... It seems that it isn't.

- Carsten

It works, but it isn't as "smart". I.e., when you omit the format from
the filename, respond_to doesn't work without further specification.

So do you use rhtml or erb?

You should move to the new naming standard. Files suffixed .rhtml are
backwards-compatible, but not preferable. Rhtml IS erb, the naming
convention just allows you to easily do more...

styles.css.erb