Using Render in my .rb file - ruby-on-rails

Hi I have some html in a file called (a partial):
_quotemail.html.erb
I Am sending an email to a user and I want to put this html in the email. I am using mailgun.
I can define my email body like so:
body = "text to go in email"
which works great but I want to instead include the HTML I have in my quotemail partial.
Whats the best way to do this?

Related

How to get the email message body with ActionMailer

I am sending an standard email with Rails like this
#mail = mail(to: registration.user.email, subject: "Registration Confirmation: #{#site.name}")
Now i need to get the message body (or html in this case) from the email. I tried the following but it does not work since it returns not the rendered email but rather the template (including ERB and Haml).
#mail.body
#mail.body.raw_source
#mail.body.encoded
It seems surprisingly difficult to do this. I need the result that a persons sees when receiving the email.
Update
The ERB and Haml i saw was an HTML comment, that's why in the logs it looked like it logged ERB instead of a rendered tempalte. So #mail.body.encoded works fine.
I tried the accepted answer but it is showing the HEADER along with HTML. To get the HTML tags only I've used below code:
#mail.html_part.body.decoded
How about #mail.body.encoded (which should give you the result for which you seek)?

How do I convert a page of HTML to a page on my Rails site?

I added an upload form so people can upload HTML files to my site. How do I parse a file of HTML to create a page of content on the site? Currently, I just need to get the title and body of a file, so I thought a full-blown parser like Nokogiri would be overkill.
#this takes in a <ActionDispatch::Http::UploadedFile>
def import(file)
#code to get title and body?
end
One of many ways to do this..
You can open and read the file from your controller assuming you saved it to an object somewhere.
#content = File.read(#your_saved_object.attachment.file_name)
And then in your view ( in Haml ) :
#content-container= #content

Thymeleaf - Configure mail subject in template

I am using Thymeleaf templates for generating email contents and send using spring mailSender. Is there any option to specify the email subject within the thymeleaf template itself?
You can define fragments in your template and render those parts only.
<div th:fragment="subject">
Mail subject
</div>
<div th:fragment="body">
Mail body
</div>
That's a basic HTML thing
Send mail
you can add also the ?body= if you want to add content in your mail.
Edit: According to your comment, you want to put a input on a page and write a subject and get it in Java.
Put a form with an input in your thymeleaf template and post it to your server, get the value in your controller and use it to send your mail.
Do you need code example for this ?

Rails3 - email template

I am fetching email content from database and storing it in variable and passsing it to email template.
i.e:
#email_content = Email.find(1)
#email_content = #email_content.content
My content is like this: "hi, how are you doing, thanks". With html <br/> tags in between the content.
Problem is, I'm getting the mail as plain text, the html tags are not working.
Could someone help me solve this?
In your view file you need to put this
<%= #email_content.html_safe %>

How to put a button to action in an email template in RoR

My application sends notification emails to users, I would like to put a button in the email that links to a certain action in a controller?
When I put regular html code (like <input type="button" .... />, I get it in the received email as string, that is, I find the html code in the email) How can I skip this trap?
It's not a perfect idea to send messages as html. By default I turn off html in my email account.
Look this screencast for a beginning: http://railscasts.com/episodes/206-action-mailer-in-rails-3. You just need to specify different view formats: html or text for plain text. But in any case it will rely on reciever email settings which format will be choosen.

Resources