Attachment_fu文件保存问题

发布于 2024-09-05 09:34:27 字数 1272 浏览 5 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安静 2024-09-12 09:34:27

你尝试过:分区选项吗?它在 /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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文