我创建了一个新的动作邮件程序,当有人点击“点击连接”按钮时,我会通过电子邮件通知我。我正在学习一个教程,并且能够通过我的“联系我们”按钮成功建立与Heroku上的SendGrid的连接。目前,当我单击按钮时,它会打开计算机的电子邮件应用程序,而不是触发SendGrip应用程序。
用户/ show.html.erb
<div class='container'>
<div class='row'>
<div class='col-md-3 text-center'>
<%= image_tag @user.profile.avatar.url, class: 'user-show-avatar' %>
</div>
<div class='col-md-6'>
<h1><%= @user.profile.first_name %></h1>
<h3><%= @user.profile.city %>, <%= @user.profile.state %>, <%= @user.profile.country %></h3>
<div class='well profile-block profile-description'>
<h4>Bio</h4>
<p><%= @user.profile.bio %></p>
<h4>Coding Languages</h4>
<p><%= @user.profile.coding_languages %></p>
<h4>Mentoring Needs</h4>
<p><%= @user.profile.mentoring_needs %></p>
</div class='connect_button'>
<a class="btn btn-primary btn-lg btn-block active" href="mailto:connections@jrdevmentoring.com" role="button">Click to Connect</a>
</div>
</div>
寄件人/ connection_mailer.rb
class ConnectionsMailer < ActionMailer::Base
default to: 'connections@jrdevmentoring.com'
def connection_email(name, email, body)
@name = name
@email = email
@body = body
mail(from: email, subject: 'Jr. Dev Mentoring Connect Form Message')
end
end
到config / environment.rb
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_startstls_auto => true
}
更新:我需要使用users / show.html.erb底部的按钮将用户发送到此表单,而不是打开我的电子邮件应用。然后,此页面上的按钮需要连接到SendGrid。
views / connections / new.html.erb
<div class="row">
<div class="col-md-4 col-md-offset-4">
<h1 class="text-center">Let's Connect</h1>
<h5 class="text-center">I'd like to connect with...</h5>
<div class="well">
<%= form_for @connection do |f| %>
<div class="form-group">
<%= f.label :your_name, "Your Name" %>
<%= f.text_field :your_name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :email, "Your Email" %>
<%= f.email_field :email, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :comments, "Connection's Name" %>
<%= f.text_area :connections_name, class: 'form-control' %>
</div>
<%= f.submit 'Submit', class: 'btn btn-default' %>
<% end %>
</div>
</div>
</div>
答案 0 :(得分:1)
您应该制作表单并将表单参数发布到控制器中的操作,以下帖子包含您需要的所有内容:Contact Form Mailer in Rails 4
答案 1 :(得分:0)
您应该从href删除邮寄地址
<a class="btn btn-primary btn-lg btn-block active"
href="mailto:connections@jrdevmentoring.com" role="button">Click to Connect</a>
这就是为什么打开电子邮件应用程序