提问人:bilel abdelmoula 提问时间:1/30/2023 更新时间:1/30/2023 访问量:162
如何使用 Rails 和 js 和 html 按钮结束电子邮件?
how to end email using Rails and js and html button?
问:
我是使用 rails 的新手,我正在尝试找出使用 html 按钮、javascript 函数和 rails 发送电子邮件的解决方案。
HTML 和 JS 代码:
<%= form_tag root_path, class: "send-email" do %>
<%= submit_tag "Click to Send Email", style: "margin: 10px; padding: 10px" %>
<% end %>
<script>
document.querySelector(".send-email").onsubmit = function(e) {
e.preventDefault()
fetch(e.target.action, {
method: "POST",
headers: {
"X-CSRF-Token": document.querySelector('meta[name="csrf-token"]').content
}
}).then(function(response) {
if (response.ok) {
window.open('/mail', '_blank')
} else {
console.error(response)
}
});
}
</script>
联系Mailer.rb
class ContactMailer < ApplicationMailer
def contact
mail(to: 'abdelmo[email protected]', subject:'testing for fly')
end
end
联系MailerPreview.rb
# Preview all emails at http://localhost:3000/rails/mailers/contact_mailer
class ContactMailerPreview < ActionMailer::Preview
def contact
ContactMailer.contact()
end
end
联系人:.html.erb
<h1>Hello this is for testing the email function</h1>
我不知道如何把所有东西连接在一起。
答: 暂无答案
评论
root_path
root_path