1
我正在使用郵箱寶石的郵件功能,但由於我很新,我不知道如何使用它。基本上我創建了以下消息控制器:Rails郵箱寶石無法發送消息
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, 」測試「, 」測試「)」 的消息控制器的一部分,但絕對不是我想要的)
另外,如果您發佈準確的堆棧錯誤,您將得到... – David
你有沒有想過這個答案?我試圖做到現在,我得到的錯誤,我有一個未定義的模型名稱。我不明白,因爲寶石不應該照顧那個?我們是否需要製作消息模型?如果是這樣,那麼桌子上需要放什麼? – Philip7899