回形针无法保存附件 [英] Paper Clip failing to save attachment

查看:61
本文介绍了回形针无法保存附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Ruby 1.9 和 Rails 2.3.4 和 Paperclip gem 来保存附件.我按照教程添加了正确的迁移,将 (has_attached_file :video) 添加到模型,制作表单(多部分)并添加 <%= f.file_field :video %> 到它...

I'm using Ruby 1.9 and Rails 2.3.4 with Paperclip gem to save attachments. and I followed tutorial by adding the proper migration, adding (has_attached_file :video) to the model, making the form (multipart) and adding <%= f.file_field :video %> to it...

当我尝试上传文件时,我查看了日志并看到:

When I try to upload a file I look in the log and I see:

[paperclip] Saving attachments.

但是文件并没有真正上传,回形针添加的额外字段都是NULL!

But the file isn't really uploaded and the extra fields that have been added by paperclip are all NULLs!!

事实上它没有抛出任何错误,这让我很困惑从哪里开始寻找可能的问题.我正在使用 MAC OSX Leopard,这可能是权限问题吗?如果是这样,我如何向我的应用授予sudo"权限?

The fact that it's not throwing any error making me confused where to start looking for possible issues. I'm using MAC OSX Leopard, is it possible that it's a permissions thing? if so how can I give "sudo" permission to my app?

任何想法是什么问题,或者我如何显示更好的日志记录以了解在哪里查找问题.

Any ideas what the problem is or how I can display better logging to know where to look for problems.

谢谢,

日志:

  SQL (0.2ms)   SET NAMES 'utf8'
  SQL (0.2ms)   SET SQL_AUTO_IS_NULL=0


Processing PostsController#create (for 127.0.0.1 at 2009-09-26 17:08:26) [POST]
  Parameters: {"authenticity_token"=>"ZhEzTVQScgZxV9KY0Eo+sG5sHwn1kHgykvy11ovvfSU=", "post"=>{"title"=>"asd fasdf ", "description"=>"asdf as fasd f", "video"=>#<File:/var/folders/RH/RHekFGKME9uDJbX4d4DG3E+++TI/-Tmp-/RackMultipart20090926-27216-m28uwg-0>, "video_link"=>"", "is_notify_when_comment"=>"0"}}
I'm in load_user
  User Columns (3.7ms)   SHOW FIELDS FROM `users`
  User Load (0.6ms)   SELECT * FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  Post Columns (3.0ms)   SHOW FIELDS FROM `posts`
WARNING: Can't mass-assign these protected attributes: video
  SQL (0.2ms)   BEGIN
  Post Create (0.4ms)   INSERT INTO `posts` (`title`, `description`, `video_link`, `is_notify_when_comment`, `view_count`, `is_ours`, `votes_up_count`, `votes_down_count`, `flag_count`, `is_deleted`, `user_id`, `created_at`, `updated_at`, `video_file_name`, `video_content_type`, `video_file_size`, `video_updated_at`) VALUES('asd fasdf ', 'asdf as fasd f', '', 0, 0, 0, 0, 0, 0, 0, 3, '2009-09-27 00:08:27', '2009-09-27 00:08:27', NULL, NULL, NULL, NULL)
[paperclip] Saving attachments.
  SQL (24.0ms)   COMMIT
Redirected to http://localhost:3000/posts/10
Completed in 477ms (DB: 32) | 302 Found [http://localhost/posts]

推荐答案

我想出了问题所在

我必须在模型中将 :video 添加到我的 attr_accessible 中,因此它不会分配该视频并且不会引发错误

I had to add :video into my attr_accessible in the model so it wasn't assigning that video and wasn't throwing an error

这篇关于回形针无法保存附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆