2012-02-13 22 views
5

Sto cercando di utilizzare ActionMailer per notificare me quando una nuova foto è stata pubblicata, ma continuo a ricevere l'errore:Rails 3 Azione Mailer non inizializzata costante

uninitialized constant CommentsController::CommentMailer 

Il commento viene aggiunto al mio database e può essere consultati. Sto anche usando Devise e le sue funzioni di posta elettronica stanno funzionando bene.

Il mio commento mailer:

class CommentMailer < ActionMailer::Base 
    def newcomment(comment) 
    mail(:to => "[email protected]", :subject => "New Comment") 
    end 
end 

e la mia sezione di controllo:

def create 
    @comment = Comment.new(params[:comment]) 
    @comment.user_id = current_user.id 

respond_to do |format| 
    if @comment.save 
    CommentMailer.newcomment(@comment).deliver 
    format.html { redirect_to @comment, notice: 'Comment was successfully created!' } 
    format.json { render json: @comment, status: :created, location: @comment } 
    else 
    format.html { render action: "new" } 
    format.json { render json: @comment.errors, status: :unprocessable_entity } 
    end 
end 
end 
+3

Il tuo messaggio di errore dice "CommentiMailer" con un s mentre il tuo codice dice CommentMailer. L'errore proviene sicuramente da questo codice? Puoi individuare la linea in cui l'errore proviene dallo stacktrace? – Shadwell

+0

Scusa era tardi quando ho fatto la mia domanda. è "CommentMailer" Not "CommentiMailer" no "s" – Steve

risposta

3

OK mio male, ho dovuto riavviare la mia applicazione rotaie dopo ho aggiunto il mailer. Sta funzionando bene ora

13

Ciò può accadere anche se il nome del file di posta elettronica è errato. UserMailer.rb interromperà mentre user_mailer.rb è ciò che è previsto.

Problemi correlati