2011-12-28 4 views
0

내 레일 애플리케이션 중 하나에서 이메일을 보내야합니다. 방금 다음과 같이 앱을 구성했습니다.레일에 루비를 사용하여 메일 보내기

레일즈 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 

:

,210

도와주세요 ...

+1

해당보기 디렉토리에 어떤 파일이 있습니까? – rkb

+0

테스트를 위해 방금보기 폴더에 contact.html.erb 빈 파일을 만들었습니다. – ramesh

답변

1

app/views에서 notifier라는 디렉토리를 만들고, 거기에 contact.html.erb 놓습니다. Rails의 규칙 중 하나는 view 디렉토리가 메일러/컨트롤러 클래스의 이름을 따를 것으로 기대한다는 것입니다.

+0

안녕하세요 rkb .. 내 app/views에 contact.html.erb라는 빈 파일을 만들었습니다.하지만 같은 오류가 표시됩니다 ... – ramesh

+0

app/views/notifier /에서 파일을 만들고 싶습니다. – rkb

관련 문제