Reputation: 1467
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?
Upvotes: 1
Views: 759
Reputation: 20232
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
Upvotes: 2
Reputation: 5449
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
Upvotes: 1
Reputation: 17812
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
Upvotes: 1