为什么即使我明确声明它只能以 JS 类型返回,我的控制器操作也只能以 HTML 格式返回?
应用程序/控制器/classrooms_controller.rb
def create
respond_to do |format|
format.js # This doesn't work.
end
end
app/views/classrooms/new.html.haml
= form_tag classrooms_path, :html => {:multipart => true}, do |f|
= text_field_tag :name
= submit_tag "Done"
app/views/classrooms/create.js.erb
alert('hi');
服务器
Started POST "/classrooms" for 127.0.0.1 at 2013-01-04 18:17:22 -0800
Processing by ClassroomsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Z+rsjO1rY2+P7VdsYd/LwiQr3DZX6r1/Dxh7JGbIOFA=", "name"=>"feed", "commit"=>"Done"}
Completed 406 Not Acceptable in 2ms
我在浏览器中得到一个没有代码的空白页面(检查了源代码)。