class FileUpload < ActiveRecord::Base
has_attachment :size => 1..1.megabyte,
:path_prefix => "public/uploadedfiles",
:storage => :file_system
end
class PostController < ApplicationController
def new_upload_file
@upload_file=FileUpload.new
@files=FileUpload.find :all
end
def do_upload
@attachable_file=FileUpload.new params[:upload_file]
if @attachable_file.save
flash[:notice]="Uploaded successfully."
redirect_to :action => :new_upload_file
end
end
end
<% if flash[:notice] %>
<%= flash[:notice] %>
<% end %>
<%
form_for(:upload_file,:url => {:action => "do_upload"},
:html => {:multipart => true}) do |form| %>
<%= form.file_field :uploaded_data,:size => 50 %>
<%= submit_tag " 上传 " %>
<% end %>
hit4
最新推荐文章于 2022-11-04 21:14:56 发布