Reputation: 303
I am working on rails 4 ruby 2 project. I had paperclip for upload files is working. But when the user doesn't upload any photo, paperclip remove the current uploaded photo and nill the field in the db.
How can I ignore the avatar field in case the user does not upload any photo and keep the previous uploaded one?
My model: has_mongoid_attached_file :avatar,:styles => { :small => "300x300#"}
Thanks a lot...
Upvotes: 0
Views: 333
Reputation: 5535
Rails 4 use strong parameters gem by default: https://github.com/rails/strong_parameters
You can check if the avatar parameter is nil in the controller and don't permit it in this case. Something like this:
def user_params
if params[:avatar]
params.require(:user).permit(:avatar,:name,...)
else
params.require(:user).permit(:name,...)
end
end
Upvotes: 1