実現したいこと
app/config/environment/production.rbファイルの設定方法を教えていただきたいです。
AWS EC2で Elastic IPを使用してブラウザを開いている場合、hostはどうしたらいいのでしょうか?
前提
ActionMailerでアカウント有効化機能を実装しようとしています。
送信メールに記載しているリンクを開くとアカウントが有効化される仕組みを作っています。
しかし、そのリンクのhostの部分でエラーが出ているのですが、設定方法がわかりません。
発生している問題・エラーメッセージ
ActionView::Template::Error (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
該当のソースコード
app/mailers/user_mailer.rb
def account_activation(user) @user = user mail to: user.email, subject: "Account activation" end
app/controllers/account_activations_controller.rb
def edit user = User.find_by(email: params[:email]) if user && !user.activated? && user.authenticated?(:activation, params[:id]) user.activate #ユーザーを有効化 log_in user flash[:success] = "Account activated!!" redirect_to user else flash[:danger] = "Invalid activation link" redirect_to root_url end end
app/controllers/user_controller.rb
def create @user = User.new(user_params) if @user.save @user.send_activation_email redirect_to root_url else render 'new' end end
app/models/user.rb
#アカウントを有効にする def activate update_attribute(:activated, true) update_attribute(:activated_at, Time.zone.now) end #有効化用のメールを送信する def send_activation_email UserMailer.account_activation(self).deliver_now end
app/config/environment/production.rb
config.action_mailer.perform_caching = false config.action_mailer.raise_delivery_errors = true config.action_mailer.asset_host = 'http://AWSのElastic IPアドレス' config.action_mailer.delivery_method = :smtp ActionMailer::Base.smtp_settings = { address: 'smtp.gmail.com', domain: 'gmail.com', port: 587, user_name: '自分のメールアドレス', password: '自分のメールアドレスのパスワード', authentication: 'plain', enable_starttls_auto: true }
補足情報(FW/ツールのバージョンなど)
ruby3.1.1
rails6.0.4
AWS EC2
回答1件