I am very new to rubies and rails (3 days and counting), so my problem is probably something stupid. However, this seems silly, which cannot be resolved by searching for answers on the Internet .:(
I create a simple blog application in the following guide: http://guides.rubyonrails.org/getting_started.html . It works great, no problem.
Then I set up SendGrid and I can send emails through it as best as possible.
Now I'm trying to use this sendgrid pearl: https://github.com/stephenb/sendgrid . I installed it using "gem install sendgrid" and it seemed to work without problems.
According to the github instructions, I just need to add “enable SendGrid” to my zip class and I'm ready to go. I did just that:
class Emailer < ActionMailer::Base include SendGrid ... end
But when I run the application, I get this error: uninitialized constant Emailer :: SendGrid
I did a couple of other things that seemed to make sense based on what I read so far:
- Added 'gem sendgrid' to my gemfile. This added three lines to my Gemfile.lock:
- Added 'require sendgrid' to environment.rb file.
However, the error still persists. One thing that may indicate a problem is that when I look at $ LOAD_PATH, it does not have a sendgrid directory. For comparison, another stone included in the same way is sqlite3, and I see the path "... / sqlite3-1.3.4 / lib", but I do not see "... / sendgrid-1.0.1 / lib".
Can anyone understand what stupidity struck me this time?
EDIT:
I found something very interesting. For me, at least ... If I go to the rails console, everything actually works fine. Here is the output of my session:
ruby-1.9.2-p290 :006 > include SendGrid => Object ruby-1.9.2-p290 :007 > sendgrid_category :use_subject_lines => :use_subject_lines ruby-1.9.2-p290 :008 > sendgrid_category "Welcome" => "Welcome" ruby-1.9.2-p290 :009 > p = Post.new(:title => "A new post", :content => "With garbage text") =>
Email sent And the category is registered in SendGrid (I could see it on the Statistics page).
So the big question is: why does my application allow me to enable SendGrid when I run commands from the console? What is the difference in environment, etc.?
Also note that emails are sent from the console, but NOT from the application stream, although development.log says that the email was sent in both situations ...