Creating a new record without uploading an image- paperclip

My users have the ability to upload a profile picture, but I don’t want
to require this upon registration.

I have a model called User, for auth and each User has_ one a Profile
The profiles model is where I’ve put my validation and keep the
information about the upload

When a new user is created, I also want to add a new record to the
profiles table,

such as

@user = User.new(params[:user])
@user.save
if @user.errors.empty?
self.current_user = @user

@profile = Profile.new(:name => @user.login, :user_id => @user.id)
@profile.save

if @profile.errors.empty?
  flash[:notice] = "Successfull"
  redirect_to('/')
else
  @errors = "Profile not created"
  render 'new'
end
else
flash[:notice]  =  "User not created fool"
redirect_to 'home'
end

The @profile.save is causing the problem because with no avatar data on
registration, the validation on the profile model is failing.

How can set up paperclip so that if I’m creating a new record then those
validations are not required?

Unless you have explicitly validate for the presence of avatars, they
are not mandatory. So, check your model to see if you have specified
that. you can also check your table to see if you have marked those
fields as not null, if so change it to null.

let me know, how it goes.

Removing that validation did allow me to create a record in the Users
model. Thanks, I figured there was a reason it had to be there as most
documentation suggests that it should be there.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs