简体   繁体   中英

In Rails while using the Devise gem how to set custom subject line?

Im trying to turn the reset password mail into a create account mail if the user is not confirmed. If the user is confirmed it will send the normal reset password link. Now the only problem I have is the subject line. I tried to change it like this :

 def reset_password_instructions(record, token, opts={})
    if record.confirmed?
        @confirm = true        
    else
        @confirm = false
        headers = { 
               :subject => "Welcome to SLMUN"
        }
    end     
  super
 end

But it didn't work. How to do it?

If you rails g devise views you can see all of the mailers that are created behind-the-scenes by Devise. You should be able to find the mailer you're after in its directory and directly edit it there.

EDIT:

You will need to use the headers method to set the headers, not a variable.

See the Rails Guides on the subject .

You just need to assign the subject through opts[:subject] like this :

def reset_password_instructions(record, token, opts={})
    opts[:subject] = 'Welcome to SLMUN'  
    super
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM