Jaap Badlands
2009-Aug-12 05:09 UTC
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?
--
Posted via http://www.ruby-forum.com/.
Rails List
2009-Aug-12 05:54 UTC
Re: Creating a new record without uploading an image- paperc
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. -- Posted via http://www.ruby-forum.com/.
Jaap Badlands
2009-Aug-12 06:27 UTC
Re: Creating a new record without uploading an image- paperc
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. -- Posted via http://www.ruby-forum.com/.