これは単純な質問であり、何度も尋ねられることを知っています。以前に確認したものはすべてレール 3.0.0 バージョンに基づいており、最新のものを使用しているため、これも質問しました。名前と電子メールのフィールドを含むユーザー登録フォームがあります。ユーザーが送信ボタンをクリックすると、ユーザーが指定した電子メールアドレスに電子メールを送信する必要があることをやりたいメールアドレスに送信されましたが、受信トレイに見つかりません。また、開発モードのアクションメーラーではメールがどのアドレスにも送信されないことも知っていますが、開発段階でこれを行いたいと考えています。私のコードは次のとおりです。
/config/initializers/setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "asciicasts.com",
:user_name => "asciicasts",
:password => "secret",
:authentication => "plain",
:enable_starttls_auto => true
}
/app/mailers/user_mailer.rb
class UserMailer < ActionMailer::Base
default :from => "eifion@asciicasts.com"
def registration_confirmation(user)
mail(:to => user.email, :subject => "Registered")
end
end
/app/controllers/users_controller.rb
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
UserMailer.registration_confirmation(@user).deliver
format.html { redirect_to(@user, :notice => 'User was successfully created.') }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
誰でも私を助けてください。