我正在尝试按照Mail_form gem 的文档添加自定义电子邮件模板。该文档指出:
要自定义使用的电子邮件模板,请创建一个名为contact.erb
. app/views/mail_form
查看此 repo 中的 lib/mail_form/views/mail_form/contact.erb 以了解默认模板的工作原理。
另外,我在 repo 中发现了这个问题并做了同样的事情:
我在初始化程序中创建了一个 mail_for.rb 文件并将 , 添加MailForm::Notifier.template_root = File.join(Rails.root, "app", "views")
到文件中。
我在视图中创建了一个 mail_form 目录并添加了一个contact.erb
文件并将默认模板复制到其中。
但是,当我重新启动服务器时,出现以下错误:
启动 WEBrick => Rails 4.2.5 应用程序开始在http://localhost:3000上开发 => 运行
rails server -h
以获得更多启动选项 => Ctrl-C 关闭服务器退出 /Users/Tony/.rvm/gems/ruby-2.2。 1/gems/actionmailer-4.2.5/lib/action_mailer/base.rb:569:inmethod_missing': undefined method
template_root=' for MailForm::Notifier:Class (NoMethodError) from /Users/Tony/Desktop/Corner_Stone/vagrant/src/cornerstone/ config/initializers/mail_form.rb:1:in<top (required)>' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in
load' 来自 /Users/Tony/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:inblock in load' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in
load_dependency ' 来自 /Users/Tony/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:inload' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/engine.rb:652:in
在 /Users/Tony/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/notifications.rb:166:in load_config_initializer' 中阻止来自 /Users/Tony/.rvm 的instrument' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/engine.rb:651:in
load_config_initializer' /gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/engine.rb:616:inblock (2 levels) in <class:Engine>' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/engine.rb:615:in
each' 来自 /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties -4.2.5/lib/rails/engine.rb:615:inblock in <class:Engine>' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/initializable.rb:30:in
instance_exec' 来自 /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/initializable.rb :30:inrun' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/initializable.rb:55:in
block in run_initializers' from /Users/Tony/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:226:inblock in tsort_each' from /Users/Tony/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:348:in
block (2 levels) in each_strongly_connected_component' from /用户/Tony/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:420:inblock (2 levels) in each_strongly_connected_component_from' from /Users/Tony/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:429:in
each_strongly_connected_component_from' 来自 /Users/Tony/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:419:inblock in each_strongly_connected_component_from' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/initializable.rb:44:in
each' 来自 /Users/Tony/.rvm/gems/ruby-2.2 .1/gems/railties-4.2.5/lib/rails/initializable.rb:44:intsort_each_child' from /Users/Tony/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:413:in
call' 来自 /Users/Tony/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort .rb:413:ineach_strongly_connected_component_from' from /Users/Tony/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:347:in
block in each_strongly_connected_component' 来自 /Users/Tony/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:ineach' from /Users/Tony/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in
call' 来自 /Users/Tony/ .rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:ineach_strongly_connected_component' from /Users/Tony/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:224:in
tsort_each' 来自 /Users/Tony/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2 .0/tsort.rb:203:intsort_each' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/initializable.rb:54:in
run_initializers' 来自 /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/application.rb:352:ininitialize!' from /Users/Tony/Desktop/Corner_Stone/vagrant/src/cornerstone/config/environment.rb:5:in
' 来自 /Users/Tony/Desktop/Corner_Stone/vagrant/src/cornerstone/config.ru:3:inrequire' from /Users/Tony/Desktop/Corner_Stone/vagrant/src/cornerstone/config.ru:3:in
块中 ' 来自 /Users/Tony/.rvm/gems/ruby-2.2.1/gems/rack-1.6。 4/lib/rack/builder.rb:55:ininstance_eval' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/builder.rb:55:in
initialize' 来自 /Users/Tony/Desktop/Corner_Stone/vagrant/src/cornerstone/config.ru:innew' from /Users/Tony/Desktop/Corner_Stone/vagrant/src/cornerstone/config.ru:in
'来自 /Users/Tony/.rvm/gems/ruby- 2.2.1/gems/rack-1.6.4/lib/rack/builder.rb:49:ineval' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/builder.rb:49:in
new_from_string' 来自 /Users/Tony/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/ lib/rack/builder.rb:40:inparse_file' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/server.rb:299:in
build_app_and_options_from_config' 来自 /Users/Tony/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/server.rb:208:inapp' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/commands/server.rb:61:in
app ' 来自 /Users/Tony/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/server.rb:336:inwrapped_app' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/commands/server.rb:139:in
log_to_stdout' 来自 /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/commands/server.rb:78:instart' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:80:in
block in server' 来自 /Users/Tony/ .rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:intap' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in
server' 来自 /Users/Tony/.rvm/gems/ruby-2.2.1 /gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:inrun_command!' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/commands.rb:17:in
'来自 /Users/Tony/Desktop/Corner_Stone/vagrant/src/cornerstone/bin/rails:9:inrequire' from /Users/Tony/Desktop/Corner_Stone/vagrant/src/cornerstone/bin/rails:9:in
'来自 /Users /Tony/.rvm/gems/ruby-2.2.1/gems/spring-1.6.4/lib/spring/client/rails.rb:28:inload' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/spring-1.6.4/lib/spring/client/rails.rb:28:in
call' 来自 /Users/Tony/.rvm/gems/ruby- 2.2.1/gems/spring-1.6.4/lib/spring/client/command.rb:7:incall' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/spring-1.6.4/lib/spring/client.rb:28:in
run' 来自 /Users/Tony/.rvm/gems/ruby-2.2.1/gems/spring-1.6。 4/bin/弹簧:49:在<top (required)>' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/spring-1.6.4/lib/spring/binstub.rb:11:in
从 /Users/Tony/.rvm/gems/ruby-2.2.1/gems/spring-1.6.4/lib/spring/binstub.rb:11:in 加载'<top (required)>' from /Users/Tony/Desktop/Corner_Stone/vagrant/src/cornerstone/bin/spring:13:in
来自 /Users/Tony/Desktop/Corner_Stone/ vagrant/src/cornerstone/bin/spring:13:in<top (required)>' from bin/rails:3:in
load' 从 bin/rails:3:in `'
当我删除文件中的代码时,一切正常mail_form.rb
,但我想根据自己的喜好自定义邮件通知。错误说 undefined method template_root=' for MailForm::Notifier:Class
,但我不知道它是什么意思。我仍在学习,所以这个错误有点过头了,任何帮助将不胜感激!谢谢!