Ruby on rails 不允许的参数:文件rails 4
在我的应用程序中,我创建了一个表单,可以上载多个文档。现在,我已经张贴了2上传文件的形式,但无法保存在数据库中由于错误。但是我得到了上面提到的所有参数。请帮我解决这个问题 在控制器中:Ruby on rails 不允许的参数:文件rails 4,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,在我的应用程序中,我创建了一个表单,可以上载多个文档。现在,我已经张贴了2上传文件的形式,但无法保存在数据库中由于错误。但是我得到了上面提到的所有参数。请帮我解决这个问题 在控制器中: def create @sr_document = SrDocument.new(sr_document_params) end def sr_document_params params.require(:sr_document).permit(:file_type, :file, :service_
def create
@sr_document = SrDocument.new(sr_document_params)
end
def sr_document_params
params.require(:sr_document).permit(:file_type, :file, :service_request_id, :file_file_name, :file_content_type, :file_file_size)
end
在日志中:
“sr_文件”=>{“文件”=>[
@tempfile=#,
@原始文件名=“Reliance Web Chat.pdf”,
@content_type=“application/pdf”,@headers=“内容处置:
表单数据;名称=\“sr\U文档[文件][]\“文件名=\”依赖
Web Chat.pdf \“\r\n内容类型:application/pdf\r\n”>
@tempfile=#\、@original\u filename=“Flipkart.pdf”、@content\u type=“application/pdf”,
@headers=“内容处置:表单数据;
名称=\“sr\U文档[文件][]\”文件名=\“Flipkart.pdf\”\r\n内容类型:application/pdf\r\n“>
]}
您正在获取文件数组,因此我认为您正在获取问题: 尝试允许您的文件属性为:
def sr_document_params
params.require(:sr_document).permit(:file_type, :file => [], :service_request_id, :file_file_name, :file_content_type, :file_file_size)
end
您正在获取文件数组,因此我认为您正在获取问题: 尝试允许您的文件属性为:
def sr_document_params
params.require(:sr_document).permit(:file_type, :file => [], :service_request_id, :file_file_name, :file_content_type, :file_file_size)
end
这些文件存储在一个数组中,文件的信息如
文件内容类型,。。是每个文件的属性,因此不能像这样获取它。
请尝试:
def create
sr_documents = []
sr_document_params[:file].each do |file|
sr_documents << SrDocument.new({ file_content_type: file.content_type,
file_size: file.size,
file: file })
end
end
def sr_document_params
params.require(:sr_document).permit(file: [])
end
def创建
sr_文件=[]
sr_document_params[:file]。每个do|file|
sr_文档这些文件存储在一个数组中,文件的信息如文件内容类型,。。是每个文件的属性,因此不能像这样获取它。
请尝试:
def create
sr_documents = []
sr_document_params[:file].each do |file|
sr_documents << SrDocument.new({ file_content_type: file.content_type,
file_size: file.size,
file: file })
end
end
def sr_document_params
params.require(:sr_document).permit(file: [])
end
def创建
sr_文件=[]
sr_document_params[:file]。每个do|file|
sr_documents unpermited参数:filefile
是sr_documents
表中的字段吗?您能给我们看一下表单吗
?不允许的参数:filefile
是sr\u文档
表中的一个字段?你能给我们看一下表单吗?
中的语法错误:params.require(:sr_文档)。permit(文件:[])中的语法错误:params.require(:sr_文档)。permit(文件:[])数组和散列参数必须在末尾,在:service\u request\u id,:file\u file\u name,…
之后,尽管看起来没有使用其他参数。语法错误在:params.require(:sr\u document)。permit(file:[])尝试执行此“params.require(:sr\u document)。permit!”数组和哈希参数必须在:service\u request\u id,:file\u file\u name,…
之后的末尾,虽然看起来没有使用其他参数。