Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10639 (new defect)

Opened 2 years ago

2.0.2 .rhtml compatibility issue. Javascript not returned for text/javascript requests

Reported by: glennfu Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: 2.0.2 javascript rjs format respond_to
Cc:

Description

Using the following in the 'join' action of a controller

respond_to do |format|
  format.html { render :layout => 'join' }
  format.js
end

Making an AJAX call (text/javascript in the header) should result in the 'format.js' line returning join.rjs as formatted javascript.

In my testing I found that the html format was instead returned. Renaming join.rjs -> join.js.erb DID return the file, but NOT formatted into javascript.

Instead, renaming join.rhtml -> join.html.erb solved the problem. Now my join.rjs is properly executed.

Note: All of this code worked properly BEFORE upgrading to 2.0.2 (I was either on 1.8.x or 2.0 edge pre-2.0 release last time I verified it working, not exactly sure which.)