簡體   English   中英

Rails中的ActionController UnknownFormat錯誤4

[英]ActionController UnknownFormat Error in rails 4

我在鐵軌上有問題。

  1. 查看(index.html.erb)

     <div id="container" style="margin:0 auto;"> <div style="float:left; height: 300px; width: 300px" align="center"> <%= form_tag("/java/select", :method => "post", :remote => true) do %> Deivce1 <%= radio_button_tag "devices", "1"%><br> Deivce2 <%= radio_button_tag "devices", "2"%><br> Deivce3 <%= radio_button_tag "devices", "3"%><br> <%= submit_tag "On/Off" %> <% end %> </div> </div> <div id="statelist"></div> 
  2. 控制器(java_controller.rb)

     class JavaController < ApplicationController skip_before_filter :verify_authenticity_token def select @device = params[:devices] respond_to do|format| format.js end end end 
  3. js文件(select.js.erb)

     $('#statelist').empty().append('<%= j render 'statelist'%>'); 
  4. html文件(_statelist.html.erb)

     Selected device is <%= @device %> 
  5. 根文件(rootes.rb)

     root "java#index" post "java/select" => "java#select" 

我認為我具有操作ajax的所有組件。 另外,我通常會事先使用類似的語法。

但是,在這種情況下,當我單擊“開/關”按鈕時,Unknownformat錯誤消息將出現在網頁中。

該錯誤表示“ respond_do |格式|” 控制器上的線路。

問題是什么 ?? 感謝您的關注。


  • 記錄...

     Started POST "/java/select" for 127.0.0.1 at 2014-08-14 17:48:55 +0900 Processing by JavaController#select as HTML Parameters: {"utf8"=>"✓", "devices"=>"2", "commit"=>"On/Off"} Completed 406 Not Acceptable in 6ms ActionController::UnknownFormat (ActionController::UnknownFormat): app/controllers/java_controller.rb:14:in `select' Rendered /usr/lib/jruby/jruby-1.7.13/lib/ruby/gems/shared/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_source.erb (6.0ms) Rendered /usr/lib/jruby/jruby-1.7.13/lib/ruby/gems/shared/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (14.0ms) Rendered /usr/lib/jruby/jruby-1.7.13/lib/ruby/gems/shared/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (19.0ms) Rendered /usr/lib/jruby/jruby-1.7.13/lib/ruby/gems/shared/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (291.0ms) 

只需刪除

 respond_to do|format|
     format.js
  end

塊。 在您的情況下,它將根據rails的默認值自動加載select.js部分。 我不確定,但也許您需要將路徑更改為

/java/select.js 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM