0

I am using rails 6 with action mailbox and want to send an email that shows the user changes made to a model. Rails has "dirty" methods such as record.changes which shows original value and new value. However, this is stored in the instance and is lost when doing a "deliver_later".

Controller update action:

OrderMailer.send_order_update(@order).deliver_later

Mailer:

def send_order_update(order)
    emails = []

    @order = order
    @contact = @order.contact
    @user = @order.user

    emails.push @contact.email if @contact.email
    emails.push @user.email if @user.email

    subject = "Order #" + @order.id.to_s + " Update"
    from = "My App <orders@myapp.com>"
    mail(from: from, to: emails, bcc: bcc, subject: subject)
end

Mailer View:

<b>Changes</b> <br>

<%= @order.changes.each do |key, value| %>
    <p><%= key.titleize %>: <span style="text-decoration:line-through;"><%= value[0] %></span> <%= value[1] %></p>
<% end %>

How can I get the record's changes accessible in the view when doing deliver later?

-- Update -- I failed to mention that I do have a has_many relationship that I need to know the changes on as well. Order Line items.

karns
  • 5,391
  • 8
  • 35
  • 57

0 Answers0