Actionmailer - heroku app

This is a newbie question so please excuse me, I have been working with
rails, but this is the first time i am trying to require gems from a
heroku app that does not include rails - just a plain Ruby app. ok I
have a app.rb file looking like this:

require "sinatra"
require 'koala'
require 'action_mailer'
ActionMailer::Base.raise_delivery_errors = true

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
   :address => "smtp.sendgrid.net",
   :port => 587,
   :domain => "MYDOMAIN",
   :authentication => :plain,
   :user_name => "USER_NAME",
   :password => "PASSWORD",
   :enable_starttls_auto => true
  }
ActionMailer::Base.view_paths= File.dirname(__FILE__)

class TestMailer < ActionMailer::Base

  default :from => "MY_EMAIL"

  def welcome_email
    mail(:to => "MY_EMAIL", :subject => "Test mail", :body => "Test mail
body")
  end
end
What I would like to do is run

TestMailer::deliver_test_email
in the console and get the details or run

TestMailer::deliver_test_email.deliver
to send a test email

but all i get is :

NameError: uninitialized constant Object::TestMailer
I have included actionmailer in the Gemfile and its also in the
Gemfile.lock

I am sure it is something straight forward for an experienced Ruby dev,
but I am struggling could anyone help me please?

Thanks

···

--
Posted via http://www.ruby-forum.com/.

Should be:

    TestMailer.deliver_test_email

no?

The deliver_test_email method is a class method, so you call it by passing the 'deliver_test_email' method call to 'TestMailer' class by using a period '.' in between.

You are using :: which is telling Ruby to look up the constant "deliver_test_email" within the module TestMailer which is why it is throwing an error, as there is no module called TestMailer, only a class called TestMailer.

Mikel Lindsaar

···

On 24/08/2013, at 8:06 AM, jon goodey <lists@ruby-forum.com> wrote:

TestMailer::deliver_test_email
in the console and get the details or run

What I would like to do is run

TestMailer::deliver_test_email in the console and get the details or run

This should be:

   TestMailer.deliver_test_email

The deliver_test_email method is a class method, so you call it by passing the 'deliver_test_email' method call to 'TestMailer' class by using a period '.' in between.

You are using :: which is telling Ruby to look up the constant "deliver_test_email" within the module TestMailer which is why it is throwing an error, as there is no module called TestMailer, only a class called TestMailer.

Mikel Lindsaar

Thank you both, I had got over my problem using Mail, but I am going to
attempt actionmailer again, I appreciate you picking up my errors in
calling the method I have spent a good part of the week, studying Ruby
classes and methods :slight_smile:

···

--
Posted via http://www.ruby-forum.com/.

I don't believe the issue is using the '::' vs. '.' notation. Although it
is more idiomatic in Ruby to call methods using the '.' style, '::' is
perfectly acceptable as well.

Object.new.object_id
Object::new::object_id

A few things I'm noticing:

* Based on the NameError you are receiving, I'm curious how you are
accessing the console? Just using IRB will not work without manually
calling 'require' or 'load' on your application's ruby file. Have you
written a custom console rake task or something along those lines? Are you
using the `bundle console` CLI (http://bundler.io/v1.3/bundle_console.html\)?

* Depending on the version of 'actionmailer' you are using, the
'deliver_test_email' method name may be incorrect. Recent versions of
'actionmailer' would need to be called using 'TestMailer.test_email.deliver'

* Lastly, the method in your example code is called 'welcome_email' while
the code you provided that would send the email is referencing 'test_email'

Good luck!

···

On Sun, Aug 25, 2013 at 7:57 AM, Mikel Lindsaar <raasdnil@gmail.com> wrote:

> What I would like to do is run
>
> TestMailer::deliver_test_email in the console and get the details or run

This should be:

   TestMailer.deliver_test_email

The deliver_test_email method is a class method, so you call it by passing
the 'deliver_test_email' method call to 'TestMailer' class by using a
period '.' in between.

You are using :: which is telling Ruby to look up the constant
"deliver_test_email" within the module TestMailer which is why it is
throwing an error, as there is no module called TestMailer, only a class
called TestMailer.

Mikel Lindsaar

--
Ryan Cook
720.319.7660