简体   繁体   English

回形针不会仅通过控制台将化身保存到用户表单中

[英]Paperclip is not saving avatar to user with a form only via console

I am one of those sad people that cannot get Rails 3.2.6, Devise and Paperclip to play happiely together. 我是无法让Rails 3.2.6,Devise和Paperclip一起快乐玩耍的那些悲伤的人之一。 I am using a normal HTML-form to testing to create a user and at the same time uploading an avatar. 我正在使用普通的HTML表单进行测试,以创建用户并同时上传头像。 According to the log, all looks fine but the image is not uploaded to Amazon S3 and the image details is not saved to the user. 根据日志,一切看起来都很好,但是图像未上传到Amazon S3,并且图像详细信息未保存到用户。

This is the output from Heroku logs directly after I submitted: 这是我提交后直接从Heroku日志中获得的输出:

2012-08-16T20:29:16+00:00 app[web.1]: Started POST "/api/v1/users" for 90.224.160.143 at 2012-08-16 20:29:16 +0000
2012-08-16T20:29:16+00:00 app[web.1]: Processing by Api::V1::UsersController#create as JSON
2012-08-16T20:29:16+00:00 app[web.1]:   Parameters: {"email"=>"eee@eee.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "username"=>"eee", "avatar"=>#<ActionDispatch::Http::UploadedFile:0x000000060fa310 @original_filename="farmer.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"avatar\"; filename=\"farmer.png\"\r\nContent-Type: image/png\r\n", @tempfile=#<File:/tmp/RackMultipart20120816-2-1oz8ytm>>}
2012-08-16T20:29:16+00:00 app[web.1]: [paperclip] Saving attachments.
2012-08-16T20:29:16+00:00 app[web.1]: [paperclip] Saving attachments.
2012-08-16T20:29:16+00:00 app[web.1]: [paperclip] Saving attachments.

This is the attachment code that I use in the User model: 这是我在用户模型中使用的附件代码:

has_attached_file :avatar,
      :storage => :s3,
      :s3_credentials => "#{Rails.root}/config/s3.yml",
      :bucket => "appprofilepictures",
      :styles => { :medium => "300x300>", :thumb => "100x100>"},
      :path => 'photos/:id/:style/:id.:extension'

This is the attr_accessible: 这是attr_accessible:

attr_accessible :avatar, :firstname, :lastname, :username, :email, :password, :password_confirmation, :remember_me, :authentication_token

This is my html form code: 这是我的html表单代码:

<form name='profile' action='http://example.com/users' method='post' enctype="multipart/form-data">
<input type="text" name="email" />
<input type="text" name="password" />
<input type="text" name="password_confirmation" />
<input type="text" name="username" />
<input type="file" name="avatar" />
<input type="submit" value="Send" />
</form>

I can manually create a user using in Heroku console and THEN it uploads. 我可以使用Heroku控制台手动创建用户,然后上传该用户。

It looks as though you are missing a couple pieces from your :has_attached_file for uploading to S3. 似乎您缺少:has_attached_file的一些片段,无法上传到S3。 If I remember correctly, the last time I set this up, it wouldn't upload without these. 如果我没有记错的话,那么我上一次进行设置时,没有这些设置就不会上传。

:url            => ':s3_alias_url',
:s3_host_alias  => "<your-bucket-name>.s3.amazonaws.com",

That solved my problem the last time I set up Paperclip with S3. 上一次我使用S3设置Paperclip时,这解决了我的问题。 Also check out the documentation on what is required. 另外,请查看有关所需文件的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM