ruby on rails - wrong number of arguments (0 for 3..6) -
i using mailboxer gem , looking have questions sent users inbox can view , answer question.
i receiving argument error wrong number of arguments (0 3..6)
. points line @message = current_user.send_message.new(:subject => "you have question #{@question.sender_id}",
i trying use send message instance since original line of code @message = current_user.messages.new(:subject => "you have question #{@question.sender_id}"
submit question notifications table, not connect conversations table.
questions controller:
def create @question = question.new(params[:question]) if @question.save #original code @message = message.create @message = current_user.send_message.new(:subject => "you have question #{@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 saved successfully. thanks!' else render :new, alert: 'sorry. there problem saving question.' end end
you getting error because send_message
method (provided mailboxer gem) requires 3..6 arguments , not sending arguments it.
also, looking @ code, seems trying save message
record question
. so, @message
should set as:
@message = current_user.message.new(:subject => "you have question #{@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
note used current_user.message.new
instead of current_user.send_message.new
.
edit
for using send_message
, @ least need pass 3 arguments:
send_message(recipient, "body", "subject")
where recipient
person receiving message.
i not sure why chaining new
method after send_message
(as called create new instance of class
).
you can call send_message
follows:
@message = current_user.send_message(@question.recipient_id, @question.question, "you have question #{@question.sender_id}")
Comments
Post a Comment