Rails部分更新ActionController :: UnknownFormat

时间:2014-09-27 15:55:12

标签: ruby-on-rails partial-views renderpartial ujs

我正在尝试更新部分内容。在Rails 3中一切都运行得很好但是现在碰到了Rails 4.1而且我得到了ActionController :: UnknownFormat错误。我将_form.html.haml放入bootstrap 3模态。

aprs_controller.rb(**是地方代码进入,我收到错误)

class AprsController < ApplicationController
  include Transloadit::Rails::ParamsDecoder
  include AprsHelper

  respond_to :html, :json, :js

  def update 
    app = App.where('events._id' =>  BSON::ObjectId.from_string(params[:eventid])).first
    unless  app.check_user_failed == true
      event = app.events.detect { |pr| pr.id.to_s == params[:eventid] }
      apr = event.aprs.detect { |pr| pr.id.to_s == params[:id] } 
      isvalid = check_video_validity(params[:transloadit], event)
      if isvalid == true
        videos = transloadit_file_uploads(params[:transloadit], apr.upload)
        @aprs=nil
        if videos.present?
          apr.upload = nil
          apr.upload = videos 
        else
          flash.now[:error] = "The time of video is wrong"
          return
        end    
        if apr.save  
          event = app.events.detect { |pr| pr.id.to_s == params[:eventid] }
          blank = event.aprs.map{|evt| evt.upload; evt.upload.blank?}
          unless blank.include? true
            event.status = 4
            event.save
          end
          **respond_to do |format| 
            @aprs = event.aprs 
            format.js     
          end**
        end
      else
        flash.now[:error] = "vieo is not valid"
        respond_to do |format| 
          @aprs = nil
          format.js     
        end
      end
    else
      flash.now[:error] = "user failed"   
    end 
  end

  private 
  def apr_params
    params.required(:apr).permit(:upload)
  end 
end

update.js.erb

$('#update_container').html("<%= j render 'form',  :locals => {:aprs => @aprs} %>");

路由

  resources :aprs 

_form.html.haml

#update_container
    - if @aprs.present?
        - @aprs.each_with_index do |apr,index|   
            = bootstrap_form_for apr, :remote=> true,   html: {"data-remote" => 'true', 'data-method' => 'post', :id => "showapr#{apr.id}" , "data-type" => :json,    class: 'form-horizontal' } do |f|
                = hidden_field_tag :eventid, apr.event.id
                = transloadit :video_encode
                .fileupload.fileupload-new.pull-left{"data-provides" => "fileupload", style: "padding-right: 5px;"}  
                    .fileupload-preview.thumbnail{:style => "width: 140px; height: 140px;"}
                        - if apr.upload.present?
                            - if apr.upload["thumbs"].present?
                                %img{ :src => apr.upload["thumbs"][0], :style => "width: 140px;height: 140px;"}
                        -else
                            %img{"data-src" => "holder.js/140x140/text:Lorem ipsum/social", :src => "", :style => "width: 140px;height: 140px;"}/
                    - if apr.event.app.check_user_failed == false &&  (apr.event.start_time.day == Time.zone.now.day)
                        %div
                            %span.btn.btn-default.btn-file
                                %span.fileupload-new Select image
                                =f.file_field "upload#{apr.id}" , accept: 'video/flv,video/avi,video/mov,video/mp4,video/mpg,video/wmv,video/3gp,video/asf,video/rm,video/swf',  :data => {:max_file_size => 30.megabytes}
                        = transloadit_jquerify "showapr#{apr.id}", :wait => true, :modal=>true,  :triggerUploadOnFileSelection=> true 
    -else
        = label_tag :error_label, "time doesn't fit to update time", class: 'control-label' 

产生此错误:

 ActionController::UnknownFormat - ActionController::UnknownFormat:
      actionpack (4.1.6) lib/action_controller/metal/mime_responds.rb:440:in `retrieve_collector_from_mimes'
      actionpack (4.1.6) lib/action_controller/metal/mime_responds.rb:256:in `respond_to'
      app/controllers/aprs_controller.rb:40:in `update'
      actionpack (4.1.6) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
      actionpack (4.1.6) lib/abstract_controller/base.rb:189:in `process_action'
      actionpack (4.1.6) lib/action_controller/metal/rendering.rb:10:in `process_action'
      actionpack (4.1.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
      activesupport (4.1.6) lib/active_support/callbacks.rb:113:in `call'
      activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
      activesupport (4.1.6) lib/active_support/callbacks.

我也注册了所有mime类型(即使它们已注册)

Mime::Type.register "text/html", :html, %w( application/xhtml+xml ), %w( xhtml )
Mime::Type.register "text/plain", :text, [], %w(txt)
Mime::Type.register "text/javascript", :js,
  %w(application/javascript application/x-javascript)
Mime::Type.register "text/css", :css
Mime::Type.register "text/calendar", :ics
Mime::Type.register "text/csv", :csv

Mime::Type.register "image/png", :png, [], %w(png)
Mime::Type.register "image/jpeg", :jpeg, [], %w(jpg jpeg jpe pjpeg)
Mime::Type.register "image/gif", :gif, [], %w(gif)
Mime::Type.register "image/bmp", :bmp, [], %w(bmp)
Mime::Type.register "image/tiff", :tiff, [], %w(tif tiff)

Mime::Type.register "video/mpeg", :mpeg, [], %w(mpg mpeg mpe)

Mime::Type.register "application/xml", :xml, %w(text/xml application/x-xml)
Mime::Type.register "application/rss+xml", :rss
Mime::Type.register "application/atom+xml", :atom
Mime::Type.register "application/x-yaml", :yaml, %w( text/yaml )

Mime::Type.register "multipart/form-data", :multipart_form
Mime::Type.register "application/x-www-form-urlencoded", :url_encoded_form

Mime::Type.register "application/json", :json,
  %w(text/x-json application/jsonrequest)

Mime::Type.register "application/pdf", :pdf, [], %w(pdf)
Mime::Type.register "application/zip", :zip, [], %w(zip)

以前在rails 3中工作的所有内容都没有改变代码。

更新操作后的服务器日志

Completed 200 OK in 320ms (Views: 308.7ms)


Started PATCH "/aprs/5429cf4663616e0f6d100000" for 127.0.0.1 at 2014-09-30 00:30:18 +0300
Processing by AprsController#update as HTML
  Parameters: {"transloadit"=>"{\"ok\":\"ASSEMBLY_COMPLETED\",\"message\":\"The assembly was successfully completed.\",\"assembly_id\":\"c0bbb2b0481f11e4bb7fe3cde209aa37\",\"parent_id\":null,\"assembly_url\":\"http://api2.ebeny.transloadit.com/assemblies/c0bbb2b0481f11e4bb7fe3cde209aa37\",\"assembly_ssl_url\":\"https://ebeny.transloadit.com/assemblies/c0bbb2b0481f11e4bb7fe3cde209aa37\",\"bytes_received\":258018,\"bytes_expected\":258018,\"client_agent\":\"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/36.0.1985.125 Chrome/36.0.1985.125 Safari/537.36\",\"client_ip\":\"85.100.75.234\",\"client_referer\":\"http://0.0.0.0:3000/apps/5429cf4563616e0f6d010000\",\"start_date\":\"2014/09/29 21:29:54 GMT\",\"is_infinite\":false,\"has_dupe_jobs\":false,\"upload_duration\":4.538,\"execution_start\":\"2014/09/29 21:29:59 GMT\",\"execution_duration\":18.362,\"notify_start\":null,\"notify_url\":null,\"notify_status\":null,\"last_job_completed\":\"2014/09/29 21:30:17 GMT\",\"notify_duration\":null,\"fields\":{},\"running_jobs\":[],\"bytes_usage\":1374741,\"executing_jobs\":[],\"started_jobs\":[],\"files_to_store_on_s3\":0,\"queued_files_to_store_on_s3\":0,\"parent_assembly_status\":null,\"params\":\"{\\\"template_id\\\":\\\"8f64b330a16f11e394d06b3e241b8964\\\"}\",\"uploads\":[{\"id\":\"c3485100481f11e494cc9bab5ef2bbe3\",\"name\":\"IMG_1561.MOV\",\"basename\":\"IMG_1561\",\"ext\":\"mov\",\"size\":257409,\"mime\":\"video/quicktime\",\"type\":\...........
flags=[]
                         COMMAND      database=approachmachine_development command={:getlasterror=>1, :w=>1} runtime: 2.2516ms
Completed 406 Not Acceptable in 80ms

ActionController::UnknownFormat - ActionController::UnknownFormat:
  actionpack (4.1.6) lib/action_controller/metal/mime_responds.rb:440:in `retrieve_collector_from_mimes'
  actionpack (4.1.6) lib/action_controller/metal/mime_responds.rb:256:in `respond_to'
  app/controllers/aprs_controller.rb:30:in `update'
  actionpack (4.1.6) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.1.6) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.1.6) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.1.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.1.6) lib/active_support/callbacks.rb:113:in `call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:282:in `block (2 levels) in halting_and_conditional'
  activesupport (4.1.6) lib/active_support/core_ext/time/zones.rb:47:in `use_zone'
  app/controllers/application_controller.rb:23:in `set_user_time_zone'
  activesupport (4.1.6) lib/active_support/callbacks.rb:424:in `block in make_lambda'
  activesupport (4.1.6) lib/active_support/callbacks.rb:281:in `block in halting_and_conditional'
  activesupport (4.1.6) lib/active_support/callbacks.rb:299:in `block (2 levels) in halting'
  i18n (0.6.11) lib/i18n.rb:256:in `with_locale'
  app/controllers/application_controller.rb:19:in `set_locale'
  activesupport (4.1.6) lib/active_support/callbacks.rb:424:in `block in make_lambda'
  activesupport (4.1.6) lib/active_support/callbacks.rb:298:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:229:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:229:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
  activesupport (4.1.6) lib/active_support/callbacks.rb:86:in `run_callbacks'
  actionpack (4.1.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.1.6) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.1.6) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.1.6) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.1.6) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.1.6) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.1.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.1.6) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  actionpack (4.1.6) lib/abstract_controller/base.rb:136:in `process'
  actionview (4.1.6) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.1.6) lib/action_controller/metal.rb:196:in `dispatch'
  actionpack (4.1.6) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.1.6) lib/action_controller/metal.rb:232:in `block in action'
  actionpack (4.1.6) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
  actionpack (4.1.6) lib/action_dispatch/routing/route_set.rb:50:in `call'
  actionpack (4.1.6) lib/action_dispatch/journey/router.rb:73:in `block in call'
  actionpack (4.1.6) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.1.6) lib/action_dispatch/routing/route_set.rb:678:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  meta_request (0.3.4) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  meta_request (0.3.4) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  bullet (4.13.2) lib/bullet/rack.rb:12:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  i18n-js (2.1.2) lib/i18n-js/middleware.rb:11:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack-mobile-detect (0.4.0) lib/rack/mobile-detect.rb:164:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  http_accept_language (2.0.2) lib/http_accept_language/middleware.rb:13:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/rack/error_collector.rb:50:in `traced_call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/rack/agent_hooks.rb:26:in `traced_call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/rack/browser_monitoring.rb:23:in `traced_call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/rack/developer_mode.rb:48:in `traced_call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
   () home/caner/.rvm/gems/ruby-2.1.2/bundler/gems/client_side_validations-e431ba00e2d7/lib/client_side_validations/middleware.rb:17:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.5.2) lib/rack/etag.rb:23:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/flash.rb:254:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.1.6) lib/active_support/callbacks.rb:82:in `run_callbacks'
  actionpack (4.1.6) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  better_errors (2.0.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.0.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.0.0) lib/better_errors/middleware.rb:57:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack-contrib (1.1.0) lib/rack/contrib/response_headers.rb:17:in `call'
  meta_request (0.3.4) lib/meta_request/middlewares/headers.rb:16:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  railties (4.1.6) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.6) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.6) lib/rails/rack/logger.rb:20:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  activesupport (4.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  actionpack (4.1.6) lib/action_dispatch/middleware/static.rb:64:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  railties (4.1.6) lib/rails/engine.rb:514:in `call'
  railties (4.1.6) lib/rails/application.rb:144:in `call'
  railties (4.1.6) lib/rails/railtie.rb:194:in `method_missing'
  newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  thin (1.6.2) lib/thin/connection.rb:86:in `block in pre_process'
  thin (1.6.2) lib/thin/connection.rb:84:in `pre_process'
  thin (1.6.2) lib/thin/connection.rb:53:in `process'
  thin (1.6.2) lib/thin/connection.rb:39:in `receive_data'
  eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
  thin (1.6.2) lib/thin/backends/base.rb:73:in `start'
  thin (1.6.2) lib/thin/server.rb:162:in `start'
  rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
  rack (1.5.2) lib/rack/server.rb:264:in `start'
  railties (4.1.6) lib/rails/commands/server.rb:69:in `start'
  railties (4.1.6) lib/rails/commands/commands_tasks.rb:81:in `block in server'
  railties (4.1.6) lib/rails/commands/commands_tasks.rb:76:in `server'
  railties (4.1.6) lib/rails/commands/commands_tasks.rb:40:in `run_command!'
  railties (4.1.6) lib/rails/commands.rb:17:in `<top (required)>'
  bin/rails:4:in `<main>'

1 个答案:

答案 0 :(得分:0)

试试这个,如果这对你有用..

我在我的应用程序中做过类似的事情。

respond_to :html, :json, :js

..................................

respond_with(@users) do |format|
      format.json { render :json => @user.as_json }
      format.html
      format.js
    end