2011-12-28 144 views
0

在我的一个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:

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 2011-12-28 06:52:13

+0

为了测试,我刚在我的视图文件夹中创建了一个空白的contact.html.erb文件 – ramesh 2011-12-28 08:43:31

回答

1

创建一个名为notifierapp/views目录下,并将其放置contact.html.erb那里。 Rails的惯例之一是它期望视图目录以邮件/控制器类命名。

+0

嗨rkb ..我刚创建了一个名为contact.html.erb在我的应用程序/视图中的空白文件..但显示相同的错误... – ramesh 2011-12-29 06:34:19

+0

您想要在app/views/notifier /中创建文件。 – rkb 2012-01-29 20:40:04