我正在将 Mailboxer gem 用于消息传递功能,但由于我很新,我不太确定如何使用它。基本上我创建了以下消息控制器:
class MessagesController < ApplicationController
before_action :set_message, only: [:new, :create]
def new
@message = Message.new
end
def create
current_user.send_message(@recipient, message_params(:body, :subject))
redirect_to conversations_path
end
private
def set_message
@recipient = User.find(params[:recipient_id])
end
def message_params
params.require(:message).permit(:body, :subject)
end
end
然后我的看法:
<h1>New Message</h1>
<%= simple_form_for(@message, html: {class: "form-horizontal"}) do |f| %>
<%= f.error_notification %>
<%= f.input :subject %>
<%= f.input :body, as: :text, input_html: { rows: "3"} %>
<div class="form-actions">
<%= f.button :submit, class: "btn btn-primary" %>
</div>
<% end %>
但是我不能发送消息......(顺便说一句,我可以发送消息是控制台,并且还用“current_user.send_message(@recipient,“test”,“test”)”替换部分消息控制器,但绝对不是我想要的是)