2016-12-14 2 views
1

のための未定義のメソッド `ヘルパー」私は工夫とシンプルなレール5のアプリケーションを持っていると私はサインアップしようとするたびに、私は次のエラーを取得する:Railsの5:NoMethodError:MyMailer

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

エラーが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 

このクラスがアプリケーションヘルパーを見つけることができない理由はありますか?

+0

なぜ「include ApplicationHelper」を実行しないのですか? – dp7

答えて

2

を含める必要があります方法ですあなたのDBのテーブルを探して、それを元に戻すことができます。

class MyMailer < ApplicationMailer 
    ..... 
end 
1

Railsアプリケーションにあるすべてのモデルには、複数のバージョンのモデル名に基づいて名前が付けられたテーブルが存在する必要があります。だからあなたのケースでは、モデルの名前はMyMailerなので、my_mailersという名前のテーブルを作成する必要があります。

rails g migration create_my_mailers 
+0

'' method_missing ':未定義のメソッド 'helper' for MyMailer(接続を確立するために 'MyMailer.connection'を呼び出します):Class(NoMethodError)' – jonhue

+0

あなたはなぜ「ヘルパー:アプリケーション」を書いていますか?あなたは 'ApplicationHelper'からのメソッドを、' include ApplicationHelper'を書きます。 –

1

エラーは、あなたのメーラーでヘルパーを呼び出しているためです。メーラーにアプリケーションヘルパーまたはヘルパーを含める場合は、 "include"キーワードを使用する必要があります。

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

これは、あなたがそれは本当にモデルとは対照的に、メーラーであればApplicationRecordとは反対に、あなたはおそらくそれが起こっている他、ApplicationMailerから継承する必要があるアプリケーションヘルパー

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