Devise Not Building Resource Correctly With Delegated Methods

- - posted in Uncategorized

User model delegates email to another model – which is actually an Oracle view.

The issue is that when devise builds the resource, its not delegating that method, and its just trying to find based upon that delegated method.

—–

Solution:  I overrode the create method in Devise’s confirmations controller (POST /resource/confirmation) to find and build the resource myself.

The following isn’t exactly what I did, but paraphrases enough that hopefully its useful.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class ConfirmationsController < Devise::ConfirmationsController

\# POST /resource/confirmation  
def create
resource = find\_user\_by_email(params\[:user\]\[:email\])
resource.resend\_confirmation\_token if user.persisted?

\# The rest of create method  
end

protected

def find\_user\_by_email(email)
\# Custom find based upon oracle view  
&#8230;

\# At the end return the resource  
return resource
end
end

Then I manually resent the confirmation token email using:

user.resend_confirmation_token if user.persisted?