我必须启用/安装什么才能让我的respond_to块返回js?
Rails 4.2.0
ruby 2.2 (也尝试了4.0...我降级以匹配设置为工作...)控制台返回错误:
在2毫秒内不能接受由CameraController#show处理为超文本标记语言完成406
ActionController::UnknownFormat (ActionController::UnknownFormat):
http://apidock.com/rails/Mime提到js是Rails的默认mime类型。我尝试将它添加到头文件中,但在控制台中返回了一条消息,告诉我不需要将它包含在头文件中……我遗漏了什么?
#camera_controller.rb
class CameraController < ApplicationController
# respond_to :js #I have tried using this...
def show
respond_to do |format|
format.js #{render 'show.js.erb'} #I have tried this too..
end
end
end
# 'home/sidebar.html.haml'
...
# =link_to "Menu Items", menu_items_index_path, :handlers => [:erb], :formats => [:js], remote:true
=link_to "Camera", camera_show_path, remote: true
...
# 'config/routes.rb'
...
get 'camera/show'
...
# camera/show.js.erb
$("#main_view").html("<%= escape_javascript(render :partial => 'camera/show')%>") 发布于 2015-01-06 15:46:51
而不是
=link_to "Camera", camera_show_path, remote: true尝试使用
%a{href: "/camera/show.js", class: 'btn', 'data-remote' => true}如果这不起作用,请在您的相机/show.js.erb中添加
window.location="#{cameras_path}"https://stackoverflow.com/questions/27791445
复制相似问题