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:
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
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.
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
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::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.