Search code examples
ruby-on-railsreact-rails

Rails mailer: generating an email without a user model


I am creating a basic app using react-rails. There are no models involved, but I do have a need to generate emails through a simple form that looks like this:

enter image description here

Since I am using React, I need to generate an AJAX Post request and point it towards my rails mailer. In all the rails mailer examples I've seen, the mail is sent when a new user is created (in the users post path). I don't have a need for this. Is it possible to treat my mailer like a controller and post directly to the mailer? How would the routes look? Thanks in advance


Solution

  • You can create your own mailers.

    Take a look at the docs for ActionMailer: http://guides.rubyonrails.org/action_mailer_basics.html

    You'll probably want to call your Mailer from a Controller. If this is an appointment form you should have an AppointmentsController with some action that calls the Mailer, renders a response, and perhaps sets a notice to give the user some feedback.