我遇到了一个奇怪的问题,经过一系列研究后无法更接近。我有几个通过 Carrierwave 上传文件的表单。当我上传信息时,部分路线被切断(我认为)。
例如,我有一个多部分表单提交到:
https://domain/programs/223/add_file 作为 POST
但在提交时我收到错误
没有路由匹配 [POST]“/223/add_file”
即使我的地址栏中显示的是完整的路线。如果将完整的路线作为 GET 请求提交,则效果很好。当我运行 rake 路线时,路线显示得很好。
这是我的路线的一个子集:
resources :programs do
match "add_file" => "programs#add_file"
如果重要的话,我正在 Apache 上运行 Rails 3.2.2 和 Passenger。该问题仅发生在该生产服务器上,而不会发生在开发中。
有任何想法吗?我被困在这个问题上,因为它会影响多条路线,并且我尝试仅为该表单定义自定义路线,但没有成功。
Update:当我从表单中删除 multi-part => true 或 file_field_tag 时,它解决了问题。这仍然是一个问题,但似乎与路由无关,而与文件上传表单有关。
Create passenger_extension.rb
in the lib
包含此代码的文件夹:
乘客3
module PhusionPassenger
module Utils
protected
NULL = "\0".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 = "\0".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
然后重新启动网络服务器。
注意:我不确定这不会破坏任何其他功能,因此使用它需要您自担风险,如果您发现这种方法有任何危害,请告诉我。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)