0

I am trying to create similar functionality as this gem authlogix-rpx, which optimistically saves the session/user object even if some of the validated fields are missing.

http://github.com/tardate/authlogic_rpx/tree/master/lib/authlogic_rpx (line 167)

With this gem it's possible to create the record that does not meet validation criteria and later on call the registration_complete? method which return false if all the validations do not pass.

I am not sure how this save is taking place, in my gem (which is an add on to authlogic using oauth2) I have tried doing save(false), save_with_vaidation_false but nothign really works, the validations fail and the record get saved.

Any ideas?

Thanks

badnaam
  • 1,876
  • 4
  • 29
  • 53
  • I'm not quite sure I understand exactly what you're looking for. You want to save without validation and then check if the resource is valid after it's been saved? – aNoble Aug 22 '10 at 08:25
  • Yes. If the user is authenticating with oauth, during the first time login I want to automatically create a user account (invalid because oauth does not provide any email/username type fields), and redirect to teh profile page, right after that asking teh user to complete the profile. My app needs the email/username etc, hence I need the validations, but I just want to skip it during the oauth login, just to let the user in first. – badnaam Aug 22 '10 at 09:13

1 Answers1

0

You should be able to run user.save(false) to save the user and then use user.errors.full_messages to access the validation error messages.

Or you could provide the :on parameter to your validations to restrict them to :create, :update or both (:save)

validates_presence_of :email, :on=>:update
aNoble
  • 7,033
  • 2
  • 37
  • 33