0
我想加載在配置目錄中,由用戶選擇一個yaml文件。 我有一個觀點:爲什麼yaml文件上傳不起作用?我認爲權限問題
<h1>File Upload</h1>
<p>Upload your Yaml Configuration File</p>
<p style="color: green"><%= flash[:notice] %></p>
<%= form_for :uploadFile, :html => { :multipart => true } do |f| %>
<label for="upload_file">Select File:</label>
<%= f.file_field :upload %>
<%= f.submit "Upload", :disable_with => 'Uploading...' %>
<% end %>
,我有一個控制器:
class UploadController < ApplicationController
def uploadFile
uploaded_io = params[:uploadFile][:upload]
File.open(Rails.root.join('public', uploaded_io.original_filename), 'w') do |file|
file.write(uploaded_io.read)
end
flash.now[:notice]="File has been uploaded successfully"
end
end
當用戶選擇文件並點擊「上傳」什麼也沒有發生,文件是不是在config文件夾。我能做什麼?也許我應該使用「import yaml」並以某種方式加載它,怎麼樣?
日誌這樣說:
Started POST "/upload/uploadfile" for 127.0.0.1 at 2012-11-08 10:51:46 +0100
Processing by UploadController#uploadfile as HTML
Parameters: {"utf8"=>"âœ「", "authenticity_token"=>"5FKgZJG4gKPCHXe8OqhFVZL0bu2X9zLR3sxd4ELBulA=", "uploadFile"=>{"upload"=>#<ActionDispatch::Http::UploadedFile:0x3b03ad8 @original_filename="newCases.yml", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"uploadFile[upload]\"; filename=\"newCases.yml\"\r\nContent-Type: application/octet-stream\r\n", @tempfile=#<File:C:/Users/Simo/AppData/Local/Temp/RackMultipart20121108-2664-tb7lxr>>}, "commit"=>"Upload"}
[1m[35mSetting Load (0.0ms)[0m SELECT "settings".* FROM "settings" WHERE "settings"."id" = ? LIMIT 1 [["id", 1]]
Rendered upload/uploadfile.html.erb within layouts/upload (0.0ms)
Completed 200 OK in 0ms (Views: 0.0ms | ActiveRecord: 0.0ms)
我試過了,但是沒有什麼變化...... –
是否config文件夾中有正確的permisssions –
我有Windows 7和我做:config/properties/attributes /我刪除了只讀的檢查,我確定了。但如果我追溯它的方式,它仍然是隻讀的。我必須這樣做?爲什麼它不會改變? –