Forum: Ruby on Rails ActionMailer Error - Please Help!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1e2dd87a31c5d3e07adc9efa375f4dc4?d=identicon&s=25 hreyaatnh (Guest)
on 2006-03-14 22:56
I'm trying to send an email to myself when someone comments on my site.
Here's my code, if you don't mind, could you tell me if you see
something wrong?

#environment.rb
# Include your application configuration below
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.server_settings = {
  :address => "mail.mydomain.com",
  :domain => "mail.mydomain.com",
  :port    => 25,
  :authentication => :login,
  :user_name => "myuname",
  :password => "mypwd" }
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.default_charset = "utf-8"

#model - notifier.rb
class Notifier < ActionMailer::Base
def comment_alert(post)
  # Email header info MUST be added here
  @recipients = "me@somewhere.com"
  @from = "ryan@mydomain.com"
  @subject = "New Comment"

  # Email body substitutions go here
  @body["first_name"] = "Fname"
  @body["last_name"] = "Lname"
  @body["title"] = post.title
end
end

#controller
def comments
    content = Content.find(params[:id])
    comment = Comment.new(params[:comment])
    content.comments << comment
    content.save
    #call to send the email after the comment is saved
    Notifier::deliver_comment_alert(content)
    redirect_to :back
end

#view - notifier.rhtml
<p>
Hello <%= @first_name %> <%= @last_name %>,

There's a new comment on <%= @title %>.
</p>


I'm getting an "Application error (Rails)" error.  If you see something
wrong here, can you help me out please???  I really appreciate it.
Thanks!
5b132632f47e8c7e2a83157cef4649c8?d=identicon&s=25 Agnieszka Figiel (agnessa)
on 2006-03-14 23:42
hreyaatnh wrote:
> I'm trying to send an email to myself when someone comments on my site.
> Here's my code, if you don't mind, could you tell me if you see
> something wrong?
>
> #environment.rb
> # Include your application configuration below
> ActionMailer::Base.delivery_method = :smtp
> ActionMailer::Base.server_settings = {
>   :address => "mail.mydomain.com",
>   :domain => "mail.mydomain.com",
>   :port    => 25,
>   :authentication => :login,
>   :user_name => "myuname",
>   :password => "mypwd" }
> ActionMailer::Base.perform_deliveries = true
> ActionMailer::Base.raise_delivery_errors = true
> ActionMailer::Base.default_charset = "utf-8"
>
> #model - notifier.rb
> class Notifier < ActionMailer::Base
> def comment_alert(post)
>   # Email header info MUST be added here
>   @recipients = "me@somewhere.com"
>   @from = "ryan@mydomain.com"
>   @subject = "New Comment"
>
>   # Email body substitutions go here
>   @body["first_name"] = "Fname"
>   @body["last_name"] = "Lname"
>   @body["title"] = post.title
> end
> end
>
> #controller
> def comments
>     content = Content.find(params[:id])
>     comment = Comment.new(params[:comment])
>     content.comments << comment
>     content.save
>     #call to send the email after the comment is saved
>     Notifier::deliver_comment_alert(content)
>     redirect_to :back
> end
>
> #view - notifier.rhtml
> <p>
> Hello <%= @first_name %> <%= @last_name %>,
>
> There's a new comment on <%= @title %>.
> </p>
>
>
> I'm getting an "Application error (Rails)" error.  If you see something
> wrong here, can you help me out please???  I really appreciate it.
> Thanks!


Hi,

it seems that your view should be "notifier/comment_alert.rhtml" and
this could be causing the error. in any case try looking in your log
what the error actually is about.

--
Agnieszka Figiel
This topic is locked and can not be replied to.