加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 发布/放置请求的路由错误(乘客标头)

发布时间:2020-12-17 03:22:32 所属栏目:百科 来源:网络整理
导读:我遇到了一个奇怪的问题,经过一系列研究后不能再接近了.我有几种通过Carrierwave上传文件的表单.当我上传信息时,部分路线会被切断(我认为). 例如,我有一个多部分表单提交到: https:/domain/programs/223/add_file as POST 但在提交时我收到错误 No route ma
我遇到了一个奇怪的问题,经过一系列研究后不能再接近了.我有几种通过Carrierwave上传文件的表单.当我上传信息时,部分路线会被切断(我认为).

例如,我有一个多部分表单提交到:

https:/domain/programs/223/add_file as POST

但在提交时我收到错误

No route matches [POST] “/223/add_file”

即使我的地址栏中的内容是完整的路线.如果将完整路线作为GET请求提交,则可以正常工作.当我运行rake路线时,路线显示就好了.

这是我的路线的一个子集:

resources :programs do
  match "add_file" => "programs#add_file"

如果重要的话,我在Apache上使用Passenger运行Rails 3.2.2.问题只发生在这个生产服务器上,从不在开发中.

有任何想法吗?我坚持这个,因为它影响多个路线,我已经尝试为那个形式定义一个没有运气的自定义路线.

更新:
当我删除多部分=> true或表单中的file_field_tag修复了问题.它仍然是一个问题,但似乎没有关于路由而不是文件上传的表单.

解决方法

使用以下代码在lib文件夹中创建passenger_extension.rb:

乘客3

module PhusionPassenger
  module Utils

    protected

    NULL = "".freeze

    def split_by_null_into_hash(data)
      args = data.split(NULL,-1)
      args.pop
      headers_hash = Hash.new
      args.each_slice(2).to_a.each do |pair|
        headers_hash[pair.first] = pair.last unless headers_hash.keys.include? pair.first
      end
      return headers_hash
    end

  end
end

乘客5

module PhusionPassenger
  module Utils

    # Utility functions that can potentially be accelerated by native_support functions.
    module NativeSupportUtils
      extend self

      NULL = "".freeze

      class ProcessTimes < Struct.new(:utime,:stime)
      end

      def split_by_null_into_hash(data)
        args = data.split(NULL,-1)
        args.pop
        headers_hash = Hash.new
        args.each_slice(2).to_a.each do |pair|
          headers_hash[pair.first] = pair.last unless headers_hash.keys.include? pair.first
        end
        return headers_hash
      end

      def process_times
        times = Process.times
        return ProcessTimes.new((times.utime * 1_000_000).to_i,(times.stime * 1_000_000).to_i)
      end
    end

  end # module Utils
end # module PhusionPassenger

然后在’config / application.rb’中执行:

class Application < Rails::Application
  ...
  config.autoload_paths += %W(#{config.root}/lib)
  require 'passenger_extension'
end

然后重新启动Web服务器.

注意:我不确定这是否会破坏任何其他功能,因此请自行承担风险,如果您发现此方法有任何损害,请告诉我.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读