Attachment_fu文件保存问题
Attachment_fu 插件有点旧,但我必须修改一个旧的应用程序,并且不能使用其他插件,如回形针等。所以这里是代码,不用多说
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/
目录中。我已经检查了提交目录的权限。
我缺少什么?
非常感谢
Attachment_fu plugin is kind of old, but I have to modify an old app and I can't use another plugin like paperclip etc. So here's the code without further 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
When the form is submitted, the database fields "content_type" and "filename" get updated and display the correct values, but the file does not appear in public/submissions/
directory. I have checked the permissions on the submissions directory.
What am I missing?
Many Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你尝试过:分区选项吗?它在 /0000/0001/image.jpg 等目录中获取文件分区。 默认值为true。让它假。我没有尝试过..但我认为你错过了这个选项...
have u tried the :partition option. it gets files partition in directories like /0000/0001/image.jpg. The default value is true. Make it false. i didn't try it.. but i think u missed this option...