1
votes

I have a simple rails 5 application with devise and whenever I try to signup, I get the following error:

NoMethodError in Devise::RegistrationsController#create undefined method `helper' for MyMailer(Table doesn't exist):Class

The error occurs in line 2:

class MyMailer < ApplicationRecord 
    helper :application # gives access to all helpers defined within `application_helper`.
    include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
    default template_path: 'devise/mailer' # to make sure that your mailer uses the devise views
end

Do you have any idea why this class cannot find my application helpers?

3
Why don't you do include ApplicationHelper ?dp7

3 Answers

2
votes

if it really is a Mailer as opposed to a Model, you should probably inherit from ApplicationMailer as opposed to ApplicationRecord, else it is going to be be looking for tables in your DB to back it.

class MyMailer < ApplicationMailer
   .....
end 
1
votes

For every model you have in your Rails application, there should exist a table, named after the plural version of the name of the model. So in your case, since the name of your model is: MyMailer so you should create a table named: my_mailers.

rails g migration create_my_mailers
1
votes

The error is because you are calling helper in your Mailer. If you want to include the application helper or any helper in your Mailer you have to use the "include" keyword.

 class MyMailer < ApplicationRecord 
    helper :application # This line is causing the error 
    include Devise::Controllers::UrlHelpers 
    default template_path: 'devise/mailer'
end

This is how you should include your application helper

class MyMailer < ApplicationRecord 
    include ApplicationHelper
    include Devise::Controllers::UrlHelpers 
    default template_path: 'devise/mailer'
end