Question

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

J.D.

Was it helpful?

Solution

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.

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top