I am working on a ruby on rail project recently and I have to customize the devise recoverable controller by myself.
Here is the code in the devise/view
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<div class="field">
<p><%= f.label :email %></p>
<p><%= f.email_field :email, autofocus: true, autocomplete: "email" %></p>
</div>
<div class="actions">
<%= f.submit "Send me password reset instructions" %>
</div>
<% end %>
And this is the controller I am trying to make it work.
# POST /resource/password
def create
@user = User.find_by_email(params[:email])
if @user.some_condition?
PasswordMailer.with(user: @user).reset.deliver_now
redirect_to '/', notice: 'If an account with that email was found, we have sent a link to reset password'
else
super
end
end
I am trying to make devise send a different email if user meet some condition but this doesn’t work. Could someone help me out.
I am trying to find someone debug my code.
Yuan Ma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1