Reply_to do | format | format.js does not work

What do I need to enable / install in order to return a response_to block to return js?

Rails 4.2.0

ruby 2.2 (Also tried with 4.0 ... I downgraded to fit the setting as work ...) The console returns an error:

Processing with CameraController # displayed as HTML Completed 406 Not allowed in 2 ms

ActionController :: UnknownFormat (ActionController :: UnknownFormat):

http://apidock.com/rails/Mime mentions that js is a MIME DEFAULT type for Rails. I tried adding it to the header file, but 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')%>")   
+4
1

=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}"
+1

Source: https://habr.com/ru/post/1570097/


All Articles