[RUBY] Try using letter_opener_web for inquiries

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.

environment

ruby 2.6.6 Rails 6.0.3.3

Implementation

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 スクリーンショット 2020-10-31 12.41.55.png 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, スクリーンショット 2020-12-30 12.25.36.png 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. スクリーンショット 2020-12-30 12.28.04.png

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)

Articles that I used as a reference

https://papa-programing.jp/rails-contacts-function/ Rather, this article is kind, and there are many things I overlooked!

Recommended Posts

Try using letter_opener_web for inquiries
Try using libGDX
Try using Maven
Try using jmockit 1.48
Try using sql-migrate
Try using SwiftLint
Try using Log4j 2.0
Try using Axon Framework
Try using JobScheduler's REST-API
Try using java.lang.Math methods
Try using PowerMock's WhiteBox
Try using Talend Part 2
Try using Talend Part 1
Try using F # list
Try using each_with_index method
Try using Spring JDBC
Command to try using Docker for the time being
Try using GloVe with Deeplearning4j
Try using view_component with rails
Try scraping using java [Notes]
Try using Cocoa from Ruby
[Swift] Try using Collection View
Gradle settings for using JUnit 5
Try using IntelliJ IDEA once
Try using Spring Boot Security
Try Spark Submit to EMR using AWS SDK for Java
Try using gRPC in Ruby
[Rails] Try using Faraday middleware
[Processing] Try using GT Force.
[Programming Encyclopedia] §2 Try using Ruby
People using docker Try using docker-compose
Try using Redmine on Mac docker
Try using Redis with Java (jar)
[Java] Try to implement using generics
Try using the messaging system Pulsar
Try using IBM Java method tracing
Try using Hyperledger Iroha's Java SDK
[Java] Where did you try using java?
Try using Microsoft Azure SDK For SQL API of Azure Cosmos DB Service 4.6
Try running React Navigation v5 demo app using Docker + Expo (For Mac)