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:
TestMailer::deliver_test_email
in the console and get the details or run
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.
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.
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’
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.