我希望登录用户能够将他们朋友的电子邮件输入到表单输入中,单击“发送”,然后它会向他们发送邮件。这是我到目前为止所拥有的
mailer.rb
class Mailer < ActionMailer::Base
default from: "donotreply@site.net"
def invite(recipient_email, body, subject)
@recipient_email = recipient_email
@body = body
mail(to: recipient_email,
body: body
subject: 'Join me on this awesome site!')
end
end
mailer_controller
class mailerController < ApplicationController
def new
end
def create
@recipient_email = params[:recipient_email]
body = params[:invitation]
Mailer.invitation(@recipient_email).deliver
flash.now[:notice] = 'Message sent'
redirect_to root_url
end
end
new.html.erb
<%= simple_form_for(new_invitation_url) do |f| %>
<%= f.label :email %>
<%= f.input :recipient_email %>
<%= f.submit :invite %>
<% end %>
invite.html.erb
Mailer#invite
Check out this awesome site!
<%= new_user_url %>
的routes.rb
post "invites/new" => "invite#create", as: :new_invite