Attachment_fu插件有点旧,但我必须修改一个旧的应用程序,我不能使用像paperclip等其他插件。所以这里的代码没有进一步的ado
Submissions table structure
---------------------------
| content_type | varchar(255) | YES | | NULL
| filename | varchar(255) | YES | | NULL
app/models/submission.rb
------------------------
has_attachment :storage => :file_system,
:path_prefix => 'public/submissions',
:max_size => 2.megabytes,
:content_type => ['application/pdf', 'application/msword', 'text/plain']
app/models/user.rb
------------------
has_one :submission, :dependent => :destroy
app/views/user/some_action.html.erb
-----------------------------------
<% form_for :user, :url => { :action => "some_action" }, :html => {:multipart => true} do |f| %>
....
<%= file_field_tag "submission[uploaded_data]" %>
<%end%>
app/controllers/user_controller.rb
----------------------------------
@user = User.find_user(session[:user_id])
@submission = @user.submission
if request.post?
@submission.uploaded_data = params[:submission][:uploaded_data]
end
提交表单后,数据库字段“content_type”和“filename”会更新并显示正确的值,但该文件不会出现在public/submissions/
目录中。我检查了提交目录的权限。
我错过了什么?
非常感谢
答案 0 :(得分:0)
您是否尝试过 :partition 选项。它在/0000/0001/image.jpg等目录中获取文件分区。 默认值为 true 。将其设为 false 。我没试过..但我想你错过了这个选项...