我正在使用郵箱gem,我正在向用戶收件箱發送問題,以便他們可以查看和回答問題。我正在收到參數錯誤wrong number of arguments (0 for 3..6)
。它指向行@message = current_user.send_message.new(:subject => "You have a question from #{@question.sender_id}",
錯誤的參數數量(0代表3..6)
我試圖使用發送消息實例,因爲代碼@message = current_user.messages.new(:subject => "You have a question from #{@question.sender_id}"
的原始行將提交問題到通知表,但不連接到會話表。
問題控制器:
def create
@question = Question.new(params[:question])
if @question.save
#Original code @message = Message.create
@message = current_user.send_message.new(:subject => "You have a question from #{@question.sender_id}",
#Original code :sender_id
:notification_id => @question.sender_id,
#Original code :recipient_id
:receiver_id => @question.recipient_id,
:body => @question.question)
@question.message = @message
@question.save
redirect_to questions_path, notice: 'Your question was saved successfully. Thanks!'
else
render :new, alert: 'Sorry. There was a problem saving your question.'
end
end
我們可以看到'send_message'方法的實現? – MrYoshiji
'send_message'只在問題控制器的創建操作中。另一個位置在Messages控制器內部用於創建操作'current_user.send_message(@recipient,params [:body],params [:subject])''。 –
這就是它,在你的評論你使用'send_message'方法3個參數,但在你的創建方法你使用'current_user.send_message.new'(使用send_message 0參數,而不是3..6) – MrYoshiji