Rails mailboxer gem, send message to user using form

怎甘沉沦 提交于 2019-12-03 22:15:49

The controller to send a message from a form:

class MessageController
  # GET /message/new
  def new
    # display form
  end

  # POST /message/create
  def create
    recipient = User.find(params[:recipient_id])
    current_user.send_message(recipient, params[:body], params[:subject])
  end
end

Form view:

<%= form_tag({controller: "messages", action: "create"}, method: :post) do %>
  <%= text_field_tag :subject %>
  <%= text_area_tag :body %>
  <%= submit_tag 'Send email' %>
<% end %>

A field for the recipient is missing in this example.

you need to have the basic knowledge in Actionmailer in rails take a look at the actionmailer

link:

guides.rubyonrails.org/action_mailer_basics.html
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!