[英]Paperclip is not saving the avatar attached
I've done the migration I have 我已经完成了迁移
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/missing/:style.png"
in my model, and im using 在我的模型中,我正在使用
<%= form_for @user, :as => :user, :url => user_path, :html => { :multipart => true } do |form| %>
<%= form.file_field :avatar %>
<div class="actions">
<%= form.submit %>
</div>
To save the avatar uploaded and 要保存上传的头像和
<%= image_tag @user.avatar.url %>
<%= image_tag @user.avatar.url(:medium) %>
<%= image_tag @user.avatar.url(:thumb) %>
To display them all, but when I submit the new avatar it is not getting saved, I'm using 要全部显示它们,但是当我提交新的头像时,它并没有被保存,我正在使用
@user = User.create(params[:user])
in the create so it should be saving, what could be the problem? 在创建时应该保存,这可能是什么问题?
<%= form_for @user, :validate => true, :html => { :multipart => true } do |f|%>
<div class="field">
<%= f.label :username %><br />
<%= f.text_field :username, :disabled => 'disabled' %><br />
<%= f.label :full_name %><br />
<%= f.text_field :full_name%><br />
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<%= f.file_field :avatar %>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>
ruby-1.9.2-p290 :002 > user = User.first
ruby-1.9.2-p290 :004 > user.avatar
=> /images/missing/original.png
Nothing is getting changed 一切都没有改变
avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil>
您需要将:avatar
添加到attr_accessible
列表中。
I assume that everything else for user is being saved properly? 我认为用户的其他所有内容均已正确保存?
The only thing that comes to my mind is, maybe you're using attr_accessible
to protect from mass assignment and you forgot to add : avatar_file_name, :avatar_content_type, :avatar_file_size
... to the whitelist? 我想到的唯一一件事是,也许您正在使用attr_accessible
来防止批量分配,却忘记将avatar_file_name, :avatar_content_type, :avatar_file_size
...添加到白名单了?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.