I'm attempting to follow the documentation for the Mail_form gem to add a custom email template. The documentation states:
To customize the e-mail template that is used create a file called contact.erb
in app/views/mail_form
. Take a look at lib/mail_form/views/mail_form/contact.erb in this repo to see how the default template works.
Also, I found this issue in the repo and did the same:
I created a mail_for.rb file in initializers and added MailForm::Notifier.template_root = File.join(Rails.root, "app", "views")
, to the file.
I created a mail_form directory in views and added a contact.erb
file and copied the default template to it.
However, when I restart the server I get the following error:
Booting WEBrick => Rails 4.2.5 application starting in development on http://localhost:3000 => Run
rails server -h
for more startup options => Ctrl-C to shutdown server Exiting /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' from /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' from /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
block in load_config_initializer' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.5/lib/active_support/notifications.rb:166:ininstrument' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/railties-4.2.5/lib/rails/engine.rb:651:in
load_config_initializer' from /Users/Tony/.rvm/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' from /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' from /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 /Users/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' 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' from /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' from /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' from /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' from /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' from /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' from /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
' from /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
block in ' from /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' from /Users/Tony/Desktop/Corner_Stone/vagrant/src/cornerstone/config.ru:innew' from /Users/Tony/Desktop/Corner_Stone/vagrant/src/cornerstone/config.ru:in
' from /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' from /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' from /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' from /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' from /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' from /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' from /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
' from /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
' from /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' from /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' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/spring-1.6.4/bin/spring:49:in<top (required)>' from /Users/Tony/.rvm/gems/ruby-2.2.1/gems/spring-1.6.4/lib/spring/binstub.rb:11:in
load' from /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
require' from /Users/Tony/Desktop/Corner_Stone/vagrant/src/cornerstone/bin/spring:13:in<top (required)>' from bin/rails:3:in
load' from bin/rails:3:in `'
Everything works when I remove the code in the mail_form.rb
file, but I want to customize the mail notification to my liking. The error says undefined method template_root=' for MailForm::Notifier:Class
, but I don't know what it means. I'm still learning so this error is a little over my head, Any help would be greatly appreciated! Thanks!