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
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.
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?
has_attached_file :avatar
Added
def user_params
params.require(:user).permit(:avatar)
end
to my UsersController to fix the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With