LoginSignup
tacky4
@tacky4 (Tacky4 .)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

下書き

解決したいこと

ここに解決したい内容を記載してください。

例)
Ruby on RailsでQiitaのようなWebアプリをつくっています。
記事を投稿する機能の実装中にエラーが発生しました。
解決方法を教えて下さい。

発生している問題・エラー

出ているエラーメッセージを入力

例)

NameError (uninitialized constant World)

または、問題・エラーが起きている画像をここにドラッグアンドドロップ

ビュー関連のコード

route.rb
Rails.application.routes.draw do
  get '/'=>"home#top"
  post 'users/create'
end
users_controller.erb
class UsersController < ApplicationController
  def create
    @user=User.new(
      name: params[:name],
      email: params[:eemail]
      )

    if @user.save #ユーザーのインスタンスが新しく生成されて保存されたら
      ContactMailer.send_when_signup(@user).deliver #
      redirect_to("/")
    else
      render "/"
    end
  end
end
/home/top.html.erb
<%= form_tag("/users/create") do %>
名前
<input name="name">
メールアドレス
<input name ="email">
<input type="submit"></input>
<% end %>

メール周りの機能

config.development.rb
  #--- 追記 ---#
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    port:                 587,
    address:              'smtp.gmail.com',
    domain:               'gmail.com',
    user_name:            '<hogehoge0@gmail.com>',
    password:             '<hogehoge>',
    authentication:       'login',
    enable_starttls_auto: true
  }
application_mailer.rb
class ApplicationMailer < ActionMailer::Base
  default from: '管理人<hogehoge@gmail.com>'
  layout 'mailer'
end
contact_mailer.rb
class ContactMailer < ApplicationMailer
  def send_when_signup(user) #メソッドに対して引数を設定
    @user = user #ユーザー情報
    mail(to: @user.email, subject: '【サイト名】 お問い合わせありがとうございます')
  end
end
send_when_signup.html
<h2><%= @user.name %></h2>
 <p>この度は、お問い合わせありがとうございました。<br>
 以下でご質問の回答となっておりますでしょうか。</p>

  <p><%= @answer %></p>

  <p>今後とも XXX をよろしくお願いいたします。</p>

自分で試したこと

ここに問題・エラーに対して試したことを記載してください。

0

No Answers yet.

Your answer might help someone💌