2

我正在关注 StackOverflow 帖子中引用的简单联系表单的教程。教程在这里: http: //matharvard.ca/posts/2011/aug/22/contact-form-in-rails-3/

一切都是复制/粘贴并更改我的域和邮件设置的一些值。遇到两个非常奇怪的错误:当我第一次提交联系表时,我得到一个:

堆栈级别太深

Rails.root:/用户/我/应用程序

应用程序跟踪 | 框架跟踪 | 全跟踪

加载以下文件时发生此错误:

邮件

邮件/解析器/rfc2822_obsolete

如果我在不重新启动 rails 应用程序的情况下重新提交,我会得到:

未初始化的常量 Mail::Ruby19

Rails.root:/用户/我/应用程序

应用程序跟踪 | 框架跟踪 | 全跟踪

app/mailers/notifications_mailer.rb:1:in `'

app/controllers/contact_controller.rb:11:in `create'

加载以下文件时发生此错误:

邮件

我觉得可能相关的部分是:

class NotificationsMailer < ActionMailer::Base
  default :from => "feedback@mydomain.com"
  default :to => "me@gmail.com"

  def new_message(message)
    @message = message
    mail(:subject => "mydomain Feedback")
  end
end

class Message
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming

  attr_accessor :name, :email, :subject, :body

  validates :name, :email, :subject, :body, :presence => true
  validates :email, :format => { :with => %r{.+@.+\..+} }, :allow_blank => true

  def initialize(attributes = {})
    attributes.each do |name, value|
      send("#{name}=", value)
    end
  end

  def persisted?
    false
  end
end

class ContactController < ApplicationController
  def new
    @message = Message.new
  end

  def create
    @message = Message.new(params[:message])        
    if @message.valid?
        NotificationsMailer.deliver_new_message params[:message]
      # NotificationsMailer.new_message(@message).deliver
      redirect_to(root_path, :notice => "Message was successfully sent.")
    else
      flash.now.alert = "Please fill all fields."
      render :new
    end
  end
end

其余模板非常简单且渲染良好。

另外,如果我错过了一些明显的冲突,请附加 gemfile:

source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'sqlite3'
gem 'redis', '2.1.1'
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'jade'
gem "haml", ">= 3.1.7"
gem "haml-rails", ">= 0.3.5", :group => :development
gem "hpricot", ">= 0.8.6", :group => :development
gem "ruby_parser", ">= 2.3.1", :group => :development
gem "rspec-rails", ">= 2.11.4", :group => [:development, :test]
gem "email_spec", ">= 1.2.1", :group => :test
gem "cucumber-rails", ">= 1.3.0", :group => :test, :require => false
gem "database_cleaner", ">= 0.9.1", :group => :test
gem "launchy", ">= 2.1.2", :group => :test
gem "capybara", ">= 1.1.2", :group => :test
gem "factory_girl_rails", ">= 4.1.0", :group => [:development, :test]
gem "bootstrap-sass", ">= 2.1.0.1"
gem "devise", ">= 2.1.2"
gem "cancan", ">= 1.6.8"
gem "rolify", ">= 3.2.0"
gem "simple_form", ">= 2.0.4"
gem "quiet_assets", ">= 1.0.1", :group => :development
gem "hub", ">= 1.10.2", :require => nil, :group => [:development]
gem 'paperclip'
gem 'aws-sdk'
gem 'aws-s3'
gem "high_voltage"

先感谢您。

4

1 回答 1

0

我认为 ContactController.rb 中的以下代码是罪魁祸首:

NotificationsMailer.deliver_new_message params[:message]

您实际上没有方法名称 deliver_new_message

尝试删除它,并取消注释它下面的行:

NotificationsMailer.new_message(@message).deliver

希望这可以帮助

于 2012-12-27T07:43:03.450 回答