2

我已将mailboxer gem 安装到我的rails 应用程序中。当我在控制台中使用它时,它可以成功工作。示例:current_user.send_message(User.last, "Body", "subject")

但我想知道如何使它与表单视图和控制器一起工作。我希望能够通过视图传递 send_message 参数并将其发送到消息或对话控制器。

我不知道处理这个奇妙的宝石的正确方法。提前致谢

京东

4

2 回答 2

5

控制器从表单发送消息:

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_tag({controller: "messages", action: "create"}, method: :post) do %>
  <%= text_field_tag :subject %>
  <%= text_area_tag :body %>
  <%= submit_tag 'Send email' %>
<% end %>

此示例中缺少收件人字段。

于 2013-09-06T09:49:16.720 回答
0

你需要具备rails中Actionmailer的基础知识 看看actionmailer

关联:

guides.rubyonrails.org/action_mailer_basics.html
于 2013-09-06T09:51:28.823 回答