I ran this migration:
我运行了这个迁移:
rails generate paperclip user avatar
It created this migration file:
它创建了这个迁移文件:
class AddAttachmentAvatarToUsers < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.attachment :avatar
end
end
def self.down
drop_attached_file :users, :avatar
end
end
I added this to my edit user registration view:
我将其添加到我的编辑用户注册视图中:
<div class="form-group">
<%= f.label :avatar %> <br>
<%= f.file_field :avatar, :autofocus => true, class: 'form-control' %>
</div>
When I try to upload an avatar in edit user registration, I receive this error:
当我尝试在编辑用户注册中上传头像时,我收到此错误:
ActiveRecord::UnknownAttributeError in Devise::RegistrationsController#update unknown attribute: avatar
Devise中的ActiveRecord :: UnknownAttributeError :: RegistrationsController #update unknown属性:avatar
EDITS
I added
def user_params
params.require(:user).permit(:avatar)
end
to my user model and now I don't get the error, but now the profile picture just prints out as a link. I think I can find an answer to that.
到我的用户模型,现在我没有得到错误,但现在配置文件图片只是作为链接打印出来。我想我能找到答案。
2 个解决方案
#1
13
Are you sure you're permitting the :avatar
attribute through your controller's permits? Also, have you mentioned the following line of code in your model?
您确定通过控制器许可证允许:avatar属性吗?另外,您是否在模型中提到了以下代码行?
has_attached_file :avatar
#2
3
Added
def user_params
params.require(:user).permit(:avatar)
end
to my UsersController to fix the issue.
到我的UsersController来解决问题。
#1
13
Are you sure you're permitting the :avatar
attribute through your controller's permits? Also, have you mentioned the following line of code in your model?
您确定通过控制器许可证允许:avatar属性吗?另外,您是否在模型中提到了以下代码行?
has_attached_file :avatar
#2
3
Added
def user_params
params.require(:user).permit(:avatar)
end
to my UsersController to fix the issue.
到我的UsersController来解决问题。