I have installed the mailboxer gem to my rails app. It's successfully working when i'm using it in the console. Exemple: current_user.send_message(User.last, "Body", "subject")
But i want to know how to do to make it work with a form view and a controller. I want to be able to pass the send_message arguments through a view and send it to a message or a conversation controller.
I don't know the right way to handle this fantastic gem. Thanks in advance
JD
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.