Devise Invitable and Validations -- what's the right way to do this?

Rails 3.2.14, Ruby 1.9.3, devise_invitable 1.1.8

I am trying to get invitations containing custom fields to validate their contents properly. I have tried the invite_keys hash route, as documented here: GitHub - scambra/devise_invitable: An invitation strategy for devise and unless I am doing something wrong with my Regexps, what happens is the fields are validated, but the error messages are incorrect[1].

I also tried adding regular validations on the model, but they aren't being called at all (only the built-in e-mail error is handled). When I tried adding validate_on_invite to my model, I got an error: uninitialized constant Devise::Models::ValidateOnInvite when I started the application.

Is there an example somewhere showing how to configure the model to validate custom fields on invitations?

Thanks!

Walter

1. Just to clarify what I mean by error messages are incorrect: If all the fields are left blank, there is an error on each field saying "[field name] cannot be blank". That's as expected. If any of the fields are properly filled in, then that field is listed in the errors as "[field name] is invalid", while the missing fields still say "[field name] cannot be blank". Only if all fields are properly filled in does the form submit, naturally. I would expect the fields that match their regexp to not have errors attached at all.

I’m sure you’ve found a solution or workaround to your problem by now, but for any future group members who encounter the same problem I found a pretty simple fix.

Devise Invitable’s model configuration docs don’t fully explain how to implement ‘:validate_on_invite’, but you have to set the configuration option to ‘true’ - :validate_on_invite => true.

Here’s what my devise method looks like in my User model for this to work correctly.

Include default devise modules. Others available are:

:confirmable, :lockable, :timeoutable and :omniauthable

devise :invitable, :database_authenticatable, :registerable,

:recoverable, :rememberable, :trackable, :validatable, :validate_on_invite => true

Now when I attempt to submit an invitation it is fully validating the User model before allowing the invitation to be sent and user record to be created. Looking at the docs, I’m guessing you can also enable this setting in the devise initializer with - config.validate_on_invite = true - but I haven’t tried going that route.