Reputation: 317
In a Rails app, the config Devise file has a reset_password_keys option. Is there a way to make one of the keys optional?
Currently I have this setting config.reset_password_keys = [ :email, :account_id ]
.
I would like to make the :account_id an optional key if there is no account_id present.
Upvotes: 1
Views: 1059
Reputation: 317
The following worked for me:
#Admin.rb
devise :database_authenticatable, :encryptable,
:recoverable, :rememberable, :trackable, :reset_password_keys => [:email]
Upvotes: 3
Reputation: 6773
There's an entry on Devise's wiki that deals with that. I'd suggest you do the following:
# on config/initializers/devise.rb:
config.reset_password_keys = [ :email, :account_id ]
# on User model
def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
where(account_id: conditions[:account_id], email: conditions[:email]).first
end
# on passwords/new.html.erb
<%= f.label :email %><br />
<%= f.text_field :email %></p>
<%= f.label :account_id %><br />
<%= f.text_field :account_id %></p>
Upvotes: 0