Ruby/Rails: How do you customize the mailer templates of Devise?

后端 未结 6 894
Happy的楠姐
Happy的楠姐 2020-12-08 03:45

I\'ve installed Devise for my Rails app (3.0.1) and it\'s mostly working. I just can\'t seem customize the mailer views.

  • My user model is \"User\".
相关标签:
6条回答
  • 2020-12-08 04:26

    according to devise's docs

    you should edit your config/initializers/devise.rb:

    config.scoped_views = true
    

    (it is commented by default)

    by doing so, you can customize your views for different models, rather than the global devise.

    0 讨论(0)
  • 2020-12-08 04:28

    If you want to generate JUST the email views, you can do it with: rails g devise:views [SCOPE] -v mailer. The [SCOPE] in your case is users.

    Note: I'm using Devise 4.7.3.

    0 讨论(0)
  • 2020-12-08 04:29

    To generate views by resource name

    rails generate devise:views users
    

    To generate specify views by module of recoverable

    rails generate devise:views users -v passwords
    

    To generate specify mail views only

    rails generate devise:views users -v mailer 
    

    for more details generate views

    0 讨论(0)
  • 2020-12-08 04:34

    If you are interested in not using Devise's default usage of ActionMailer and would instead like to send customized emails with an API from a service like SendGrid, Mailgun, or Postmark you will need to create a custom Mailer that subclasses Devise::Mailer and overrides its "notification" methods.

    Here is an example using Mailgun.

    0 讨论(0)
  • 2020-12-08 04:42

    Try this:

    rails generate devise:views
    
    0 讨论(0)
  • 2020-12-08 04:48

    I think you'll need to manage the Devise views yourself. Try the following in a console:

    rails generate devise:views
    

    This will generate all the views Devise uses (including mailer templates), which you can now customize.

    The mailers you're looking for should then be in 'app/views/devise/mailer'

    If you want to generate scoped views, or only a subset of them that is also possible. Per the documentation at https://github.com/plataformatec/devise#configuring-views:

    You can also use the generator to generate scoped views:

    rails generate devise:views users
    

    If you would like to generate only a few sets of views, like the ones for the registerable and confirmable module, you can pass a list of modules to the generator with the -v flag.

    rails generate devise:views -v registrations confirmations
    
    0 讨论(0)
提交回复
热议问题