Reputation: 69
What do I have to enable/install to get my respond_to block to return js?
Rails 4.2.0
ruby 2.2 (Also tried with 4.0... I downgraded to match setup as work...) The console returns error:
Processing by CameraController#show as HTML Completed 406 Not Acceptable in 2ms
ActionController::UnknownFormat (ActionController::UnknownFormat):
http://apidock.com/rails/Mime mentions that js is a DEFAULT mime type for Rails.. I tried adding it to the header file but that returned a message in the console saying that I did not need to include it in the header file... What am I missing?
#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')%>")
Upvotes: 4
Views: 2054
Reputation: 779
Instead of
=link_to "Camera", camera_show_path, remote: true
try using
%a{href: "/camera/show.js", class: 'btn', 'data-remote' => true}
If that doesn't work, in your camera/show.js.erb add
window.location="#{cameras_path}"
Upvotes: 1