Search code examples
ruby-on-railsdevise

Devise overrides custom email view


I want to sent email instructions to reset users password using devise gem. To do so I override passwords_controller

class PasswordsController < Devise::PasswordsController
  respond_to :json

  def create
    account = ::Account.find_by(email: password_reset_params[:email])
    account&.send_reset_password_instructions
    head 200
  end

  private

  def password_reset_params
    params.require(:account).permit(:email)
  end
end

with view - app/views/accounts/mailer/reset_password_instructions.html.erb

<p>Hello <%= @resource.email %>!</p>

<p>This is a password reset request, click on the link below:</p>

<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>

But instead of above email I received standard message:

Hello test@test.com!

Someone has requested a link to change your password. You can do this through the link below.

Change my password

If you didn't request this, please ignore this email.

Your password won't change until you access the link above and create a new one.

Should I change something else? in initializers/devise I've got config.mailer = 'Devise::Mailer' routes are changed:

devise_for :accounts, singular: 'account', path: '', controllers: {
passwords:     'api/v1/account/passwords',
}

Solution

  • After the suggestion in the Max's comments all I had to do was move mailer view file from app/views/accounts/mailer/reset_password_instructions.html.erb to -> app/views/devise/mailer/reset_password_instructions.html.erb