首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails:配置邮件程序时未初始化的常量库(NameError)

Rails:配置邮件程序时未初始化的常量库(NameError)
EN

Stack Overflow用户
提问于 2014-05-09 16:23:30
回答 1查看 395关注 0票数 0

我将environment.rb文件配置如下:

代码语言:javascript
复制
# Load the Rails application.
require File.expand_path('../application', __FILE__)

# Initialize the Rails application.
Rails.application.initialize!

rapp::Application.configure do
    config.action_mailer.delivery_method = :smtp

    config.action_mailer.smtp_settings = {
        address:        "smtp.gmail.com",
        port:           587,
        domain:         "gmail.com",
        authentication:     :login,         # will send password Base64 encoded
        user_name:      "myadress",
        password:       "mypass",
        enable_starttls_auto:   true
    }
end

但是,当我试图生成这样的mailer类时:

代码语言:javascript
复制
rails generate mailer MailNotifier template1 template2 template3

我发现了一个错误:

代码语言:javascript
复制
/home/usr/.../rapp/config/environment.rb:7:in `<top (required)>': undefined local variable or method `rapp' for main:Object (NameError)
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/application.rb:264:in `require'
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/application.rb:264:in `require_environment!'
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:147:in `require_application_and_environment!'
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:133:in `generate_or_destroy'
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:51:in `generate'
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'

有人能帮忙解决这个问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-09 16:44:05

将action_mailer设置为:-

代码语言:javascript
复制
http://stackoverflow.com/questions/23300150/actionmailer-not-working-when-i-change-gmail-password/23300459#23300459

environment.rb文件中删除

代码语言:javascript
复制
rapp::Application.configure do
    config.action_mailer.delivery_method = :smtp

    config.action_mailer.smtp_settings = {
        address:        "smtp.gmail.com",
        port:           587,
        domain:         "gmail.com",
        authentication:     :login,         # will send password Base64 encoded
        user_name:      "myadress",
        password:       "mypass",
        enable_starttls_auto:   true
    }
end

那就试试:-

代码语言:javascript
复制
rails generate mailer MailNotifier template1 template2 template3
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23569542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档