Reputation: 397
I have created a new Action Mailer that will allow me to be notified by email when someone clicks on the "Click to Connect" button. I'm following a tutorial and was able to successfully set up the connection with SendGrid on Heroku from my "contact us" button. Currently when I click the button it opens my computer's email app instead of triggering the SendGrip app.
users/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:[email protected]" role="button">Click to Connect</a>
</div>
</div>
mailers/connection_mailer.rb
class ConnectionsMailer < ActionMailer::Base
default to: '[email protected]'
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
}
Update: I need the button at the bottom on the users/show.html.erb to send the user to this form, instead of opening my email app. And then the button on this page needs to connect to 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>
Upvotes: 1
Views: 461
Reputation: 33
you should remove mailto from href
<a class="btn btn-primary btn-lg btn-block active"
href="mailto:[email protected]" role="button">Click to Connect</a>
that's why is opening the email app
Upvotes: 0
Reputation: 2420
You should make a form and post the form parameters to an action in a controller, the following post has everything you need: Contact Form Mailer in Rails 4
Upvotes: 1