2012-03-14 24 views
5

我在我的項目中添加了一個系統來重置用戶的密碼,並通過電子郵件發送給他,以防他忘記密碼。昨天工作正常(當我實施它時)。當我今天嘗試啓動服務器時,出現以下錯誤。Rails 3.2.1中ActionMailer中未定義的方法'default_content_type ='

=> Booting WEBrick 
=> Rails 3.2.1 application starting in development on http://0.0.0.0:3000 
=> Call with -d to detach 
=> Ctrl-C to shutdown server 
Exiting 
/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer/base.rb:437:in `method_missing': undefined method `default_content_type=' for ActionMailer::Base:Class (NoMethodError) 
from /Users/vinayshenoy/flo-server/config/environment.rb:7:in `<top (required)>' 
from /Users/vinayshenoy/flo-server/config.ru:4:in `require' 
from /Users/vinayshenoy/flo-server/config.ru:4:in `block in <main>' 
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval' 
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize' 
from /Users/vinayshenoy/flo-server/config.ru:1:in `new' 
from /Users/vinayshenoy/flo-server/config.ru:1:in `<main>' 
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval' 
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file' 
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:200:in `app' 
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands/server.rb:46:in `app' 
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app' 
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:252:in `start' 
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands/server.rb:70:in `start' 
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands.rb:55:in `block in <top (required)>' 
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands.rb:50:in `tap' 
from /Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands.rb:50:in `<top (required)>' 
from script/rails:6:in `require' 
from script/rails:6:in `<main>' 

這是我的config/environment.rb文件中

# Load the rails application 
require File.expand_path('../application', __FILE__) 

# Initialize the rails application 
FloServer::Application.initialize! 

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

如果我註釋掉ActionMailer::Base.default_content_type = "text/html"線,服務器工作沒有任何問題。但沒有它,我無法發送電子郵件。

昨天

config.action_mailer.delivery_method = :smtp 
config.action_mailer.smtp_settings = { 
:address    => "smtp.gmail.com", 
:port     => 587, 
:user_name   => 'username', 
:password    => 'password', 
:authentication  => 'plain', 
:enable_starttls_auto => true } 

我試着重新啓動的Mac我將此添加到配置/環境/ development.rb文件,運行「捆綁更新」,並沒有任何結果重新安裝護欄。

我在Ruby 1.9.3上使用Rails 3.2.1。請幫忙。

+0

DEFAULT_CONTENT_TYPE。當您嘗試發送電子郵件時,您會收到什麼錯誤?另外,您是否有適合您嘗試發送的電子郵件的附加擴展名。 (action.format.template) – AMIT 2012-03-14 06:03:10

+0

我在問題中提到昨天整個系統工作正常。直到我將該行添加到environment.rb,它才發送電子郵件。我爲html創建了視圖擴展,但沒有創建文本。 – 2012-03-14 06:07:40

回答

8

你可以試試不需要

ActionMailer::Base.default :content_type => "text/html" 
+0

它工作!謝謝!出於好奇,任何想法爲什麼早期的路線昨天工作,但不是今天? – 2012-03-14 06:05:00

+1

@VinaySShenoy:配置選項不讀取,直到服務器重新啓動;你可能已經在昨天運行了,但不得不在今天重新啓動它,這就是當更改的配置被讀取時 – fakeleft 2012-03-26 19:47:01

+0

我也有一些問題,所以我決定在這裏問你,而不是問一個新的問題。 我的項目的不同之處在於我在Environment.rb中添加了這個: ** config.action_mailer.delivery_method =:smtp | :sendmail | :test ** 我該如何處理? (謝謝你!) – 2014-02-13 18:09:31

相關問題