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.