0

I am building an application, that upon creating a customer record it will email the customer a welcome email. The message of that email is generated from a partial that merges in various data elements. I want to take the output of that partial and save it into the database so it can be viewed/recalled later.

I tried using the following in my controller.

@description = render "new_account_we"

Which I tried after reading https://guides.rubyonrails.org/layouts_and_rendering.html.

It gave me errors relating to two renders being in the controller as I have the typical respond to in my controller. Which I understand. So I can not render the partial in the controller and I do not want to show it actually on screen so I am stumped as to how to do this.

Can you give me some advice as to the best way to achieve this.

Chris Nash
  • 23
  • 1
  • 10

3 Answers3

1

Try @description = view_context.render "new_account_we"

explanation

sloneorzeszki
  • 1,274
  • 3
  • 12
  • 22
0

you can use rails helper render_to_string for storing output in a variable. you can see the details here.

wasipeer
  • 1,015
  • 11
  • 23
0

If your intention is to save all the contents along with data i.e. data + html, you can use Rails helper to generate email content with data like

in app/helpers/application_helper.rb

module ApplicationHelper
  def email_contents(some_parameters)
    # Email contents with data
  end
end

and in views you can use this like

@description = email_contents(some_parameters) 
Pramod Shinde
  • 1,802
  • 1
  • 15
  • 28