I decided to create an inquiry function for the service I am making now. I found out that there is a gem called letter opner, and I thought it would be extremely fun (I got an error on the way, but I solved it), so I decided to use it.
Looking at various articles, I was surprised to find that some of them were omitted on the premise that "this is a matter of course" (I just didn't notice), so I was in trouble, so I wrote down my memorandum as well. I will.
ruby 2.6.6 Rails 6.0.3.3
Gemfile
group :development do
gem 'letter_opener_web'
end
bundle install.
Make it all at once using scaffold.
$ rails g scaffold Contact name:string email:string content:text
rails db:migrate To do. When you access/contacts/new in the local environment If you have such a simple input screen, it's OK.
Create an Action Mailer.
$ bin/rails g mailer ContactMailer
Implement the send function.
app/mailers/contact_mailer.rb
class ContactMailer < ApplicationMailer
def contact_mail(contact)
@contact = contact
mail to: "My email address",subject: "confirmation"
end
end
I forgot to draft this article. Maybe something is missing. ..
When you send it from the contact form, The screen will switch to the screen saying that you have successfully created such an email.
Confirmation of letter_opner transmission http://localhost:3000/letter_opener You can access it with. If such a screen is displayed and there is a notification of the contents of the sent mail, the mailer is working properly.
I didn't implement it in the production environment after this! I thought, and when I tried to use sendgrid, even if I added the sendgrid add-on, I couldn't access the page. Apparently, it seems that you can only set up after newly registering sendgrid and getting login information. (Confirmed carry-over at the beginning of the year)
https://papa-programing.jp/rails-contacts-function/ Rather, this article is kind, and there are many things I overlooked!
Recommended Posts