i am using the devise for my User account where i will get all the confirmation, user password instructions etc; But i am having a condition where if user account is locked (where status is false in my scenario), he has to get a reset password link through email. This locking process is coded in other controller so we cannot use devise helpers.
my controller code:
def send_instruction
a=[]
if @answer1 a << '1' end if @answer2 a << '2' end if @answer3 a << '3' end if a.size <= 1 SiteMailer.unlock_user(current_user).deliver current_user.update_attribute(:status,false) destroy_user_session_path(current_user) flash[:error]= "Your account is locked" redirect_to new_user_session_path else redirect_to user_dashboard_path end
mailers/site_mailer.rb:
class SiteMailer < ActionMailer::Base
include Devise::Mailers::Helpers
default from: "[email protected]" def unlock_user(user)
@user = user @url = "pwd_edit" mail(to: @user.email, subject: 'Your account has been locked')
end
end
in mailer view:
Hi,
Your account with has been locked. Edit Profile: "My link (edit_user_password_url(current_user)".
When i am going through this process, I am getting "No routes found" error. And my routes are correct. Please help me out.
That's because no
current_user
is present at that time. You should try this instead