Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

model validations during invite acceptance #187

woodwardjd opened this Issue Mar 22, 2012 · 5 comments


None yet
2 participants

Currently, validations can be run on invite by setting validate_on_invite. They are always run in accept_invitation!, but before invitation_token is nul'ed out. This means, as far as I can tell, that model_instance.invited? remains true during the validations run during accept_invitation!

My use case is as follows:

## user.rb
def not_invited?
validates :email, :uniqueness => { :case_sensitivity => false }
validates :name, :presence => true
validates :institution, :presence => true, :if => :not_invited?
validates :department, :presence => true, :if => :not_invited?

That is, I want some validations on invited Users, and all of them on accepted Users.

But, the validations for a "complete" User don't get run during accept_invitation! because invited? is still true during accept_invitation!

My current cheap hack workaround is:

## user.rb
attr_accessor :completing_invite
attr_accessible :completing_invite
def not_invited?
  !invited? || (invited? && completing_invite)
<%# app/views/devise/invitations/edit.html.erb %>
<%= f.hidden_field :completing_invite, :value => true %>

Am I missing something? Is there a way to handle my use case with devise_invitable as-is (1.0.0)?

Would a patch to add something like model_instance.invited_or_accepting? be welcome? Or maybe patching so invited? is false during accept_invitation!



As I get further into my implementation I see that invited? is false when running validations during invite!, and would need to be similarly corrected.


scambra commented Mar 28, 2012

If invitation_token is nulled before validations are run, when a validation fails you won't be able to resend the form.

If invitation_token is nulled before validations are run, when a validation fails you won't be able to resend the form.

Yeah, that seems to be true. My current solution doesn't do that. It teaches the model to detect "during acceptance", giving the validations the ability to act accordingly.


scambra commented Apr 2, 2012

I would accept a patch to add invited_or_accepting?


scambra commented Apr 2, 2012

Also, I think it's better to set completing_invite in accept_invitation! instance method (first line) instead of adding a hidden field tag

@woodwardjd woodwardjd pushed a commit to woodwardjd/devise_invitable that referenced this issue Apr 3, 2012

Jason Woodward github issue #187 - add ability for validators to detect acceptance w…
…hich allows validators to be configured for pre-invite, post-invite-accept, or both

@scambra scambra closed this Apr 4, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment