2011-12-28 15 views
0

私のレールアプリケーションの1つでは、メールを送信する必要があります。私は次のように私のアプリを設定しました。ruby​​ on railsを使用してメールを送信する

私はRails v2.0を使用しています。

environment.rbに:

RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION 

# Bootstrap the Rails environment, frameworks, and default configuration 
require File.join(File.dirname(__FILE__), 'boot') 

Rails::Initializer.run do |config| 
    config.action_controller.session = { 
    :session_key => '_mailtest_session', 
    :secret  => 'key_here' 
    } 
    ActionMailer::Base.delivery_method = :smtp 
    ActionMailer::Base.smtp_settings = { 
    :address => "smtp.gmail.com", 
    :port => 25, 
    :domain => "gmail.com", 
    :authentication => :login, 
    :user_name => "[email protected]", 
    :password => "password" 
    } 

    ActionMailer::Base.default_content_type = "text/html" 
end 

モデル/ notifier.rb:私は、私はこのエラーを取得mはインデックスメソッドを呼び出すことを試みた

class Notifier < ActionMailer::Base 

    def contact(recipient, subject, message, sent_at = Time.now) 
     @subject = subject 
     @recipients = recipient 
     @from = '[email protected]' 
     @sent_on = sent_at 
     @body["title"] = 'Signup Info' 
     @body["email"] = '[email protected]' 
     @body["message"] = message 
     @headers = {} 
     return true 
    end 
end 

コントローラ/管理者

class AdministratorController < ApplicationController 
    def index 
    recipient = "[email protected]" 
    subject = "Subject" 
    message = "message" 
    Notifier.deliver_contact(recipient, subject, message) 
    end 
end 

Couldn't find template file for notifier/contact in ["D:/Rails/rails_apps/mailtest/app/views"] 

...

+1

このビューディレクトリにはどのようなファイルがありますか? – rkb

+0

テスト用に私のビューフォルダに空のcontact.html.erbファイルを作成しました – ramesh

答えて

1

app/viewsnotifierという名前のディレクトリを作成し、そこにcontact.html.erbを置く助けてください。 Railsの規則の1つは、viewディレクトリにmailer/controllerクラスの名前を付けることを期待しているということです。

+0

こんにちはrkb ..私は私のapp/viewsにcontact.html.erbという空白のファイルを作成しました..しかし、同じエラーを表示しています... – ramesh

+0

app/views/notifier /にファイルを作成します。 – rkb

関連する問題