Hey Leute,
bevor wieder ein paar GErüchte aufkommen in Sachen Finanzkrise und Co.
Ich habe die eine oder andere Frage zum ActionMailer.
Ausgangslage:
Ich lege über den Athlet Controller einen Athleten an und will nach dem
erfolgreichen speichern eine Email an mich und ihn verschicken lassen.
AthletController:
def create
@athlet = Athlet.new(params[:athlet])
respond_to do |format|
if @athlet.save
flash[:notice] = 'Athlet was successfully created.'
format.html { redirect_to(@athlet) }
format.xml { render :xml => @athlet, :status => :created,
:location => @athlet }
else
format.html { render :action => "new" }
format.xml { render :xml => @athlet.errors, :status =>
:unprocessable_entity }
end
end
end
Athlet Model
class Athlet < ActiveRecord::Base
after_create :notify_user
end
AthletMailer:
class AthletMailer < ActionMailer::Base
after_create :notify_user
def notify_user
AthletMailer.deliver_welcome_email(user)
end
def welcome_email(user)
recipients user.email
from "My Awesome Site
Notifications<notifications@example.com>"
subject "Welcome to My Awesome Site"
sent_on Time.now
body {:user => user, :url => "http://example.com/login"}
content_type "text/html"
# use some_other_template.text.(html|plain).erb instead
template "some_other_template"
end
def welcome(user)
@recipients athlet.email
@subject = "TEST User Anmeldung"
end
end
Aber irgendwie bin ich wohl zu doof dafür. Ich bekomme in jeglicher Form
immer den Fehler
undefined method `notify_user' for #<Athlet:0x23609c8>
Hat jemand mal ein Bild oder Struktorgramm, dass ich sehen kann wo der
Fehler liegt oder kann mir jemand helfen....?
Thanx
mario
--
Mario Schröder | http://www.ironschroedi.com/de/
Office: +49 361 2152062
Phone: +49 34464 62301 Cell: +49 163 27 09 807
http://www.xing.com/go/invite/6035007.9c143c
on 2009-05-12 11:28
on 2009-05-12 11:35
On Tue, 12 May 2009 11:27:20 +0200 schroedi <schroedi2001@gmail.com> wrote: > Hey Leute, > > bevor wieder ein paar GErüchte aufkommen in Sachen Finanzkrise und Co. > Ich habe die eine oder andere Frage zum ActionMailer. (...) > > Athlet Model > class Athlet < ActiveRecord::Base > after_create :notify_user > > end hier fehlt 'def notify_user' statt in AthletMailer gruesse rene
on 2009-05-12 11:47
schroedi wrote: > def notify_user > content_type "text/html" > # use some_other_template.text.(html|plain).erb instead > template "some_other_template" > end > > def welcome(user) > @recipients athlet.email > @subject = "TEST User Anmeldung" > end > end Du hast da was falsch verstanden. AthletMailer ist ja kein Model im Sinne von ActiveRecord. In diesem Fall bedeutet es, dass du deine Definition von notify_user in das Athlet Model packen muss und es ueberhaupt nicht im AthletMail brauchst. Generell braucht man in ActionMailer Klassen nur die Methoden um Emails zu schicken (hier brauchst du also nur die welcome_email Methode). Urban
on 2009-05-12 11:48
Hi, du solltest dafür einen athlete_observer benutzen. Dann musst du die Benachrichtigungslogik nicht im Model integrieren. http://api.rubyonrails.org/classes/ActiveRecord/Ob... -Alexander
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.