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.
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.
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
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...